python – selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试用selenium单击Next按钮时无法找到元素
作者:互联网
所以我试图用selenium单击下一个按钮,我尝试使用下面的代码,但结果是错误的.
元素
<input type="submit" name="submitNext" value="Next">
我的代码
driver.find_element_by_name("submitNext").click()
但随后它会输出这些错误
Traceback (most recent call last):
File "C:/Users/thomas/PycharmProjects/test/mainapp/main.py", line 194, in
<module>
visa()
File "C:/Users/thomas/PycharmProjects/test/mainapp/main.py", line 174, in visa
driver.find_element_by_name("submitNext").click()
File "C:\Users\thomas\PycharmProjects\BudgetMain\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 487, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:\Users\thomas\PycharmProjects\BudgetMain\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 955, in find_element
'value': value})['value']
File "C:\Users\thomas\PycharmProjects\BudgetMain\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Users\thomas\PycharmProjects\BudgetMain\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"submitNext"}
(Session info: chrome=66.0.3359.170)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.16299 x86_64)
任何人都有任何想法如何点击该按钮没有错误?
解决方法:
此错误消息…
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"submitNext"}
(Session info: chrome=66.0.3359.170)
(Driver info: chromedriver=2.36.540470)
…暗示ChromeDriver无法找到所需的元素.
找到所需的元素
根据您共享的HTML单击元素,您可以使用以下任一定位器策略:
> css_selector:
driver.find_element_by_css_selector("input[name='submitNext'][value='Next']").click()
> xpath:
driver.find_element_by_xpath("//input[@name='submitNext' and @value='Next']").click()
但是,您的主要问题是您使用的二进制文件之间的版本兼容性如下:
>您使用的是chromedriver = 2.36
> chromedriver=2.36发行说明明确提到以下内容:
Supports Chrome v63-65
>您使用的是chrome = 66.0
> ChromeDriver v2.38发行说明明确提到以下内容:
Supports Chrome v65-67
>您的Selenium客户端版本不为我们所知.
因此,ChromeDriver v2.36和Chrome浏览器v66.0之间存在明显的不匹配
解
>将Selenium升级到当前水平Version 3.11.0.
>将ChromeDriver升级到当前的ChromeDriver v2.38级别.
>将Chrome版本保持在Chrome v66.x级别. (as per ChromeDriver v2.38 release notes)
>通过IDE清理Project Workspace,并仅使用所需的依赖项重建项目.
>使用CCleaner工具在执行测试套件之前和之后擦除所有操作系统.
>如果您的基本Web客户端版本太旧,请通过Revo Uninstaller将其卸载并安装最新的GA和已发布的Web客户端版本.
>重新启动系统.
>执行你的@Test.
标签:python,css-selectors,selenium,selenium-webdriver,xpath 来源: https://codeday.me/bug/20190915/1806078.html