在使用 xpath 获取 H5 元素后,然后 click,总是无法触发点击事件,这边 H5 页面的元素确实是已经获取到了,另外我的 chromedriver 是 2.18.343845,跟这个版本过低有关系吗?求问,不甚感激
我也遇到过,换一种定位方式 id,name 等,或者 xpath 模糊匹配一下呢,//*[@id='form1']/div[1]/div/div[2]/ul/li[1] 前面加//,匹配后面的的
self.driver.find_element_by_xpath("//*[@id='ceList']/li[@tag='product']/div/img[(@src='img/icon/product.png')]"),这个是我需要获取的元素信息,
下面是打印日志
info: Chromedriver: Changed state to 'online'
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"33a8376e-6874-4ce5-a273-7bf8412a1467"}
info: <-- POST /wd/hub/session/33a8376e-6874-4ce5-a273-7bf8412a1467/context 200 4325.996 ms - 76 {"status":0,"value":null,"sessionId":"33a8376e-6874-4ce5-a273-7bf8412a1467"}
info: --> POST /wd/hub/session/33a8376e-6874-4ce5-a273-7bf8412a1467/element {"using":"xpath","sessionId":"33a8376e-6874-4ce5-a273-7bf8412a1467","value":"//[@id='ceList']/li[@tag='product']/div/img[(@src='img/icon/product.png')]"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/33a8376e-6874-4ce5-a273-7bf8412a1467/element] to [POST http://127.0.0.1:9515/wd/hub/session/6b0d001786795a70b92ee0706fa91287/element] with body: {"using":"xpath","sessionId":"33a8376e-6874-4ce5-a273-7bf8412a1467","value":"//[@id='ceList']/li[@tag='product']/div/img[(@src='img/icon/product.png')]"}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"6b0d001786795a70b92ee0706fa91287","status":0,"value":{"ELEMENT":"0.47495032264851034-1"}}
info: JSONWP Proxy: Replacing sessionId 6b0d001786795a70b92ee0706fa91287 with 33a8376e-6874-4ce5-a273-7bf8412a1467
info: <-- POST /wd/hub/session/33a8376e-6874-4ce5-a273-7bf8412a1467/element 200 382.237 ms - 107
info: --> POST /wd/hub/session/33a8376e-6874-4ce5-a273-7bf8412a1467/element/0.47495032264851034-1/click {"sessionId":"33a8376e-6874-4ce5-a273-7bf8412a1467","id":"0.47495032264851034-1"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/33a8376e-6874-4ce5-a273-7bf8412a1467/element/0.47495032264851034-1/click] to [POST http://127.0.0.1:9515/wd/hub/session/6b0d001786795a70b92ee0706fa91287/element/0.47495032264851034-1/click] with body: {"sessionId":"33a8376e-6874-4ce5-a273-7bf8412a1467","id":"0.47495032264851034-1"}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"6b0d001786795a70b92ee0706fa91287","status":0,"value":null}
info: JSONWP Proxy: Replacing sessionId 6b0d001786795a70b92ee0706fa91287 with 33a8376e-6874-4ce5-a273-7bf8412a1467
俺也是初学,不知道你要实现什么功能哈,我说一下我遇到的问题和怎么解决的,输入框输入完成后点击确认,我点击有时候好使,有的时候不行,我们输入框是支持回车后确认的,我直接在输入框加\n ,就不点击确认了,
WebElement 监听的不一定是 click 事件,还有 tap、touch,这几个是不一样的,你可以都试试
感谢提供思路,目前切回 native,使用 tap 获取坐标是可以正常点击了,主要我们那个 webview 的页面开发监听是用 js 写的,有可能是这个原因导致 click 事件无法响应,不过感觉使用坐标获取元素不是最好的方法,不知道有没有其他解决方法