Python Selenium find_element_by_xpath在页面中找不到现有元素

孔雀

我正在使用Python 3.6+和Selenium 3.141

我正在尝试从页面获取元素,尽管我使用的是正确的Xpath表达式(在浏览器控制台中已确认),但相同的Xpath表达式在Selenium chrome驱动程序中引发了“ NotFound”错误。

myscript.py

from selenium import webdriver


url = 'https://live.euronext.com/en/product/stock-options/AH1-DPAR'
browser = webdriver.Chrome(executable_path='./chromedriver')
browser.get(url)

try:
    
    checkbox = browser.find_element_by_xpath('//*[@id="form-options-index"]/div/div[2]')
    
except:
    pass

该脚本在find_element_by_xpath()调用方法时引发异常-即使在使用浏览器时,相同的Xpath表达式也将导致正确标识/选择元素。

为什么Xpath表达式不能与硒一起使用?我该如何解决?

杰森

页面源中缺少必需的内容-它是动态加载的,因此您需要等待直到它出现在DOM中:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = 'https://live.euronext.com/en/product/stock-options/AH1-DPAR'
browser = webdriver.Chrome(executable_path='./chromedriver')
browser.get(url)

checkbox = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="form-options-index"]/div/div[2]')))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python Selenium find_element_by_xpath找不到元素

Selenium Python find_element Xpath找不到xpath

Python:Selenium 找不到页面的 xpath

如何使用Selenium for Python将find_element_by_xpath()用于svg元素

Python Selenium 找不到元素标题(xpath)

Python selenium 在模态中找不到元素

找不到元素-Selenium -Python

Python.Selenium。找不到现有元素。如何切换帧

Selenium Python,我用xpath找不到元素-NoSuchElementException

使用 xpath 找不到元素(Python 和 selenium)

Selenium python:find_elements_by_tag_name 和循环工作但不是 find_element_by_xpath

Selenium Webdriver用python抓取动态页面找不到元素

find_element_by_xpath() 使用 Selenium 和 Python 顯示語法錯誤

Python Selenium 找不到元素或单击元素

Python Selenium 获取元素找不到元素

找不到任何元素 Selenium Python

Python Selenium Ubuntu:WebDriverWait 找不到元素

Python Selenium Webscraping返回找不到元素

Python selenium 即使等待也找不到元素

我找不到这个元素,python selenium

driver.find_element_by_xpath 不会在 selenium python 中单击我的元素

Selenium 在页面中找不到元素

在 selenium python 中找不到跨度文本

Python Selenium 找不到输入

Selenium + XPath:找不到元素

Selenium 找不到任何使用 css、xpath、name、id 的元素(python)

如何在 Selenium python 中找到页面的特定元素,因为我找不到它们

Selenium 在某些页面上的 XPATH 上找不到元素

更改XPath Selenium Python