简体   繁体   English

selenium 驱动程序,button=driver.find_element_by_xpath(“//input[@id='alpha']”) 消息:没有这样的元素:无法定位元素

[英]selenium driver, button=driver.find_element_by_xpath(“//input[@id='alpha']”) Message: no such element: Unable to locate element

i want to avoid the exception or error due to unfound button, and change a variable to stop the loop.我想避免由于未找到按钮而导致的异常或错误,并更改变量以停止循环。 i couldn't find on documentation what it really return in case of unexistant element如果元素不存在,我无法在文档中找到它真正返回的内容

while there_is_more:
    button=driver.find_element_by_xpath("//input[@id='alpha']")

    if not button :
        there_is_more=False

The goal is to stop when the button is not found目标是在找不到按钮时停止

while there_is_more:
    button=driver.find_elements_by_xpath("//input[@id='alpha']")

    if len(button)==0 :
        there_is_more=False

use find elements and check for the result list.使用查找元素并检查结果列表。

I tried this, il solved my problem perfectly我试过了,我完美地解决了我的问题

from selenium.common.exceptions import NoSuchElementException
    
    try:
        more_button=driver.find_element_by_xpath("//input[@id='alpha']")
        more_button.click()

    except NoSuchElementException:
        there_is_more= False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 硒无法使用driver.find_element_by_xpath捕获 - Can't capture by driver.find_element_by_xpath used by selenium 使用 driver.find_element_by_xpath().clear() 清除输入字段 - Clear input field with driver.find_element_by_xpath().clear() Python Selenium driver.find_element_by_xpath 在 iframe 中找不到元素 - Python Selenium driver.find_element_by_xpath can't find element within iframe 不是有效的 xpath 表达式 driver.find_element_by_xpath - not a valid xpath expression driver.find_element_by_xpath 对于 driver.find_element_by_xpath 中的 XPATH 循环不起作用 - For loop not working for XPATH in driver.find_element_by_xpath Selenium chrome 驱动程序无法定位输入元素 - Selenium chrome driver unable to locate input element 问题 "driver.find_element_by_xpath("//div[@class='example']" - Problem " driver.find_element_by_xpath("//div[@class='example']" 硒 Python 使用 driver.find_element_by_xpath() 显示 DeprecationWarnings - Seleneium Python shows DeprecationWarnings with driver.find_element_by_xpath() 为什么在 Selenium 命令 driver.find_element_by_xpath 不起作用? - Why in Selenium the command driver.find_element_by_xpath doesn't work? 为什么我的 for 循环在我的列表中途失败? Selenium webdriver,driver.find_element_by_xpath - Why is my for loop failing halfway through my list? Selenium webdriver, driver.find_element_by_xpath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM