selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试用selenium单击“下一步"按钮时无法找到元素 [英] selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element while trying to click Next button with selenium

查看:109
本文介绍了selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试用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\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)

任何人都知道如何无误地单击该按钮?

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 :

    支持 Chrome v63-65

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆