Python selenium通过xpath查找元素在页面中找不到现有元素
我正在使用Python 3.6+和Selenium 3.141 我试图从页面获取元素,尽管我使用的是正确的Xpath表达式(在浏览器控制台中确认),但相同的Xpath表达式在selenium chrome驱动程序中会引发“NotFound”错误 myscript.py 脚本在调用Python selenium通过xpath查找元素在页面中找不到现有元素,python,selenium,xpath,Python,Selenium,Xpath,我正在使用Python 3.6+和Selenium 3.141 我试图从页面获取元素,尽管我使用的是正确的Xpath表达式(在浏览器控制台中确认),但相同的Xpath表达式在selenium chrome驱动程序中会引发“NotFound”错误 myscript.py 脚本在调用find_element\u by_xpath()方法时引发异常-即使在使用浏览器时,相同的xpath表达式也会导致正确识别/选择元素 为什么Xpath表达式不能与selenium一起使用?如何修复此问题?页面源中缺少必
find_element\u by_xpath()
方法时引发异常-即使在使用浏览器时,相同的xpath表达式也会导致正确识别/选择元素
为什么Xpath表达式不能与selenium一起使用?如何修复此问题?页面源中缺少必需的内容-它是动态加载的,因此您需要等待它出现在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]')))
要单击
选择全部
复选框。使用WebDriverWait
(),等待元素可点击()并遵循Xpath
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="form-options-index"]//label[@for="select_all_dates"]'))).click()
您需要导入以下库
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait