Sai*_*ita 1 python selenium xpath
这是我试图自动执行一些点击的网站:
我尝试使用Xpath
和单击按钮FullXpath
,但仍然没有运气。
这是简单的代码:
w = webdriver.Chrome(executable_path='chromedriver.exe',
chrome_options=options)
w.get("https://quillbot.com/")
time.sleep(5)
pasteXpath = "//button[contains(@class,'outlinedPrimary') and .//span[contains(text(),'Paste Text')]]"
element = w.find_element_by_xpath(pasteXpath).click()
Run Code Online (Sandbox Code Playgroud)
但它失败并在控制台中显示以下消息:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="inOutContainer"]/div[2]/div[2]/div/div[1]/div/div/div[1]/div/div/div[2]/div/div/button/span[1]/div"}
Run Code Online (Sandbox Code Playgroud)
请告诉我如何使用 selenium 自动执行此点击。
我建议使用By
, WebDriverWait
, 和expected_conditions
代替.find_element_by_xpath
。
单击粘贴按钮后,您将收到权限提示。请参阅下文以克服它。
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 import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.chrome.service import Service
import time
import pyautogui
service = Service('C:\\Path_To_Your\\chromedriver.exe')
driver = webdriver.Chrome(service=service)
driver.get('https://quillbot.com/')
paste_button = WebDriverWait(driver, 3).until(EC.visibility_of_element_located(
(By.XPATH, "//span[text()='Paste Text']")))
paste_button.click()
time.sleep(2)
pyautogui.press('tab')
pyautogui.press('tab')
pyautogui.press('enter')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6791 次 |
最近记录: |