通过 uiatuomatior viewer 里面查看到该元素的 bounds,即该元素的坐标范围
感谢提供思路,目前切回 native,使用 tap 获取坐标是可以正常点击了,主要我们那个 webview 的页面开发监听是用 js 写的,有可能是这个原因导致 click 事件无法响应,不过感觉使用坐标获取元素不是最好的方法,不知道有没有其他解决方法
你这个是不是由于没有加等待事件导致?
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
环境配置都是 ok 的,后来又重新试修改了脚本,换成了用 find_element_by_id 获取 resourceid 是可以点击的,而使用 find_element_by_name 获取 text 不可以,但就比较奇怪的是模拟器上通过 find_element_by_name 是可以正常跑的,而真机不行