因此,我尝试使用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 :
css_selector
driver.find_element_by_css_selector("input[name='submitNext'][value='Next']").click()
xpath :
xpath
driver.find_element_by_xpath("//input[@name='submitNext' and @value='Next']").click()
但是,您的主要问题是所使用的二进制文件之间的 版本兼容性 ,如下所示:
支持 Chrome v63-65
支持 Chrome v65-67
因此, ChromeDriver v2.36* 和 Chrome浏览器 v66.0 之间存在明显的不匹配 *
@Test