25、Selenium + Python 实现 UI 自动化测试-unknown error: Element is not clickable at point (x,y)
2017-10-17 15:31
761 查看
今天遇到个有趣的问题,分享一下
一、网址:http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html
这是一个注册页,需要自动化输入用户注册信息,然后点击注册按钮
二、分析
1、第一步,看了没有iframe,该元素有id按照正常逻辑写代码
运行报错:
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,滚动页面,使提交按钮可见
运行仍然报错:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
3、再仔细看下html 代码,发现这里是个table,换xpath定位下元素。
运行成功
4、再次试验,假如使用xpath定位元素,不加滚动条滚动,看是否能执行
运行报错:
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则没问题,于是试试火狐。
运行结果:成功
那现在问题在于:
1、为什么该元素直接通过id定位不能成功,通过xpath定位就可以?
2、之前学习使用selenium定位表格的时候,看到过一句话,说先定位表格,再定位表格中的元素。难道是这个原因?貌似也不对,上面的用户名、密码同样是在表格内通过id就能找到元素。
该问题暂时未找到答案,求解。
一、网址:http://www.hsjcjwh.top/dn_biz/index.php/home/users/regist.html
这是一个注册页,需要自动化输入用户注册信息,然后点击注册按钮
二、分析
1、第一步,看了没有iframe,该元素有id按照正常逻辑写代码
from selenium import webdriver driver = 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 webdriver from time import sleep driver = 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 sleep
driver = 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就能找到元素。
该问题暂时未找到答案,求解。
相关文章推荐
- 做点击操作时的错误WebDriverException: unknown error: Element is not clickable at point (958, 207).
- unknown error: Element is not clickable at point (996, 513). Other element would re
- selenium webdriver:"Element is not clickable at point"
- 解决Selenium报错“Element is not clickable at point...”的四种方法
- python定位元素 报错 unknown error: Element is not clickable at point (1147, 395)
- Element is not clickable at point error in chrome
- 解决Selenium报错:Element is not clickable at point (x, y). Other element would receive the click
- Selenium定位元素提示Element is not clickable at point 第一篇
- Selenium 错误 Element is not clickable at point (x, y). Other element would receive the click
- webdriver 报错:Element is not clickable at point (993, 61). Other element would receive the click
- python+selenium自动化测试~打开浏览器报TypeError: 'module' object is not callable
- webdriver 报错:Element is not clickable at point (993, 61). Other element would receive the click
- Element is not clickable at point (1108, 190). Other element would receive the click
- 解决chromedriver无法click element的问题:Element is not clickable at point (326, 792.5)
- Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)
- selenium报错“Element is not clickable at point”及解决方法
- Firefox上运行自动化测试脚本提示元素无法点击“WebDriverException: Message: Element is not clickable at point“解决方法
- Uncaught TypeError: XX is not a function at HTMLInputElement.onclick
- 3、Selenium + Python 实现 UI 自动化测试-元素定位
- 35、Selenium + Python 实现 UI 自动化测试-正片7