selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element while trying to click Next button with selenium(selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试使用 selenium 单击下一步按钮时无法找到元素) - IT屋-程序员软件开发
问题描述
所以我尝试使用 selenium 单击下一步按钮,我尝试使用下面的代码,但它以错误结束.
So Im trying to I click the next button using selenium, I've tried with the code below, but it ends in error.
元素
<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 homasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 487, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:Users homasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 955, in find_element
'value': value})['value']
File "C:Users homasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriver
emotewebdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:Users homasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriver
emoteerrorhandler.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)
任何人对如何正确单击该按钮有任何想法?
Anyone have any ideas as to how to click that button without errors?
推荐答案
这个错误信息...
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 无法找到所需的元素.
...implies that the ChromeDriver was unable to locate the desired element.
根据您共享的 HTML 来单击元素,您可以使用以下任一定位器策略:
As per the HTML you have shared to click on the element you can use either of the following Locator Strategies :
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()
但是您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:
However your main issue is the version compatibility between the binaries you are using as follows :
- 您正在使用 chromedriver=2.36
- chromedriver=2.36 的发行说明明确提及以下内容:
支持 Chrome v63-65
- 您正在使用 chrome=66.0
- ChromeDriver v2.38 明确提及以下内容:
- 我们不知道您的 Selenium 客户端 版本.
- 将 Selenium 升级到当前级别版本 3.11.0.
- 将 ChromeDriver 升级到当前的 ChromeDriverv2.38 级别.
- 将 Chrome 版本保持在 Chrome v66.x 级别.(根据 ChromeDriver v2.38 发行说明)
- 清理你的项目工作区通过你的IDE和重建你的项目只需要依赖.
- 使用 CCleaner 工具清除之前和在您的测试套件执行之后.
- 如果您的基础 Web Client 版本太旧,请通过 卸载它Revo Uninstaller 并安装最新的 GA 和发布版本的 Web Client.
- 进行一次系统重启.
- 执行你的
@Test
. - Upgrade Selenium to current levels Version 3.11.0.
- Upgrade ChromeDriver to current ChromeDriver v2.38 level.
- Keep Chrome version at Chrome v66.x levels. (as per ChromeDriver v2.38 release notes)
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
- If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
- Take a System Reboot.
- Execute your
@Test
.
支持 Chrome v65-67
所以 ChromeDriver v2.36 和 Chrome 浏览器 v66.0 之间存在明显的不匹配
So there is a clear mismatch between the ChromeDriver v2.36 and the Chrome Browser v66.0
这篇关于selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试使用 selenium 单击下一步按钮时无法找到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:selenium.common.exceptions.NoSuchElementException:消息:没有
基础教程推荐
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01