25、Selenium + Python 实现 UI 自动化测试-unknown error: Element is not clickable at point (x,y)
来源:互联网 发布:琉璃神社新的域名 编辑:程序博客网 时间:2024/06/05 11:07
今天遇到个有趣的问题,分享一下
一、网址:http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html
这是一个注册页,需要自动化输入用户注册信息,然后点击注册按钮
二、分析
1、第一步,看了没有iframe,该元素有id按照正常逻辑写代码
from selenium import webdriverdriver = webdriver.Chrome()driver.get('http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html')driver.find_element_by_id('reg_butt').click()运行报错:
Traceback (most recent call last):
File "E:/python/test1/day1/test12.py", line 6, in <module>
driver.find_element_by_id('reg_butt').click()
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
元素不可见,确实,我们用js,处理下页面滚动条,再试试
2、改进,假如js,滚动页面,使提交按钮可见
from selenium import webdriverfrom time import sleepdriver = webdriver.Chrome()driver.get('http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html')js = "$(document).scrollTop(300)"driver.execute_script(js)sleep(2)driver.find_element_by_id('reg_butt').click()运行仍然报错:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
3、再仔细看下html 代码,发现这里是个table,换xpath定位下元素。
from selenium import webdriver运行成功from time import sleepdriver = webdriver.Chrome()driver.get('http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html')js = "$(document).scrollTop(300)"driver.execute_script(js)sleep(2)driver.find_element_by_xpath('//*[@id="reg_form"]/table/tbody/tr[7]/td/input').click()
4、再次试验,假如使用xpath定位元素,不加滚动条滚动,看是否能执行
from selenium import webdriver运行报错:from time import sleepdriver = webdriver.Chrome()driver.get('http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html')sleep(2)driver.find_element_by_xpath('//*[@id="reg_form"]/table/tbody/tr[7]/td/input').click()
selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (572, 679)
(Session info: chrome=61.0.3163.100)
5、为什么会报上面的错误呢?百度了一下,说是Chrome浏览器特有问题,换Firefox和IE则没问题,于是试试火狐。
from selenium import webdriverfrom time import sleepdriver = webdriver.Firefox()driver.get('http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html')sleep(2)driver.find_element_by_xpath('//*[@id="reg_form"]/table/tbody/tr[7]/td/input').click()运行结果:成功
那现在问题在于:
1、为什么该元素直接通过id定位不能成功,通过xpath定位就可以?
2、之前学习使用selenium定位表格的时候,看到过一句话,说先定位表格,再定位表格中的元素。难道是这个原因?貌似也不对,上面的用户名、密码同样是在表格内通过id就能找到元素。
该问题暂时未找到答案,求解。
- 25、Selenium + Python 实现 UI 自动化测试-unknown error: Element is not clickable at point (x,y)
- 关于selenium python Message: unknown error: Element is not clickable at point错误
- Selenium 错误 Element is not clickable at point (x, y). Other element would receive the click
- selenium模拟点击下一页出现unknown error: Element is not clickable at point (80, 60)
- 解决Selenium报错:Element is not clickable at point (x, y). Other element would receive the click
- unknown error: Element is not clickable at point (996, 513). Other element would re
- 解决selenium报错Element is not clickable at point...
- selenium webdriver:"Element is not clickable at point"
- selenium select Element is not clickable at point
- WebDriverException: unknown error: Element is not clickable at 问题解决
- 做点击操作时的错误WebDriverException: unknown error: Element is not clickable at point (958, 207).
- Selenium定位元素提示Element is not clickable at point 第一篇
- selenium报错Element is not clickable at point及四种解决方法
- selenium报错“Element is not clickable at point”及解决方法
- 解决chromedriver无法click element的问题:Element is not clickable at point (326, 792.5)
- Element is not clickable at point (1108, 190). Other element would receive the click
- webdriver 报错:Element is not clickable at point (993, 61). Other element would receive the click
- webdriver 报错:Element is not clickable at point (993, 61). Other element would receive the click
- tensorflow笔记 :常用函数说明
- getParameter和getAttribute的区别
- viewPager搭载指示器,轻松上手
- myrocks proc init梳理
- CDN技术详解
- 25、Selenium + Python 实现 UI 自动化测试-unknown error: Element is not clickable at point (x,y)
- 源码解析-post
- 面试时关于“工作可预见困难有哪些”应聘者如何巧妙回答
- android读写excel文件
- 论文阅读《Long-term Temporal Convolutions for Action Recognition》
- python读取外部数据之读取csv格式
- 自动账户确定之AUM
- 图的数据结构
- reorder-list Java code