编写selenium脚本时,会犯些错误,纪录下来,方便自己后续查看
1、定位元素时提示:
unknown error: Element is not clickable at point (580, 47). Other element would receive the click: <label for="stb_1">...</label>
提示:元素无法点击,其他的元素会接收此点击行为。
分析原因,首先肯定不是因为页面元素不存在而无法点击。
分析后得出,实际上这个页面元素是存在的,而是被另外一个弹层挡住了。
2、
selenium.common.exceptions.NoAlertPresentException: Message: no alert open
提示没有alert弹框弹出,分析得出是因为前面有个元素没有定位到,但是为什么不直接提示元素没有定位到,而是提示没有alert弹出。。。
3、
alert = driver.switch_to.alert()
TypeError: 'Alert' object is not callable
对象不能用函数形式调用,就是不能callable。 此类错误一般是由于内部函数被用作变量名时发生
4、
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
没有安装火狐浏览器的驱动,我安装环境时,只安装了chrome的驱动,安装firefox的驱动即可
5、
driver.find_element_by_id("su").click()
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (611, 28)
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.11.5 x86_64)
因为在程序中使用了set_window_size设置了窗口的大小,窗口缩小后,导致某个元素无法点击;
解决办法:将set_window_size设置的宽度调大,使driver.find_element_by_id(“su”).click()被定位的元素不被遮挡即可。
6、
tagname1 = root.getElementByTagName('browser')
AttributeError: 'Element' object has no attribute 'getElementByTagName'
在定位元素过程中,注意当获取一组标签时,element是复数,改为tagname1 = root.getElementsByTagName(‘browser’)即可;
7、
raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: './tesCase/'
这个错误很低级,然后自己还找了好久,记录一下,路径写错了,’./testCase/’,少了一个字母t