提问人:Tyler Dodgen 提问时间:11/9/2023 更新时间:11/9/2023 访问量:66
Selenium Python 脚本找不到存在的 XPATH
Selenium Python script won't find an XPATH that is present
问:
我正在尝试编写一个脚本,该脚本打开我的暂存 URL 并通过流单击/发送密钥。
我遇到了我认为表明该元素不存在的错误(消息:未知错误:result.webdriverValue.value list 在 Runtime.callFunctionOn 响应中缺失或为空)
我是一个菜鸟,只是想改善他们的生活,所以如果有人能诊断出我的剧本,我将不胜感激。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
import time
chrome_driver_path = r"C:\Users\tyler\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe"
service = Service(executable_path=chrome_driver_path)
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
try:
driver.get("my-staging-URL")
time.sleep(10)
driver.find_element("xpath", '/html/body/div[1]/div[1]/header/div[1]/div[2]/div/div[3]/div/button[2]/div/div/p').click()
time.sleep(5)
#driver.get("https://www.youtube.com/results?search_query=selenium+xpath")
except NoSuchElementException as e:
print("Element not found:", e)
input("Press any key to close the browser")
对于更多上下文,当我在 Katalon 记录器等工具中使用此 xpath 时,它工作正常。
答:
3赞
Tououououer
11/9/2023
#1
这在selenium4.1中不是正确的表达......driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/header/div[1]/div[2]/div/div[3]/div/button[2]/div/div/p').click()
评论