[英]Selenium error when trying to find xpath for “Not Now” button
我想做一個 Instagram 機器人,我還處於起步階段。 由於此錯誤,Selenium 不想單擊“Not Now”按鈕:
“selenium.common.exceptions.InvalidSelectorException:消息:無效選擇器:無法找到具有 xpath 表達式的元素 //button[text() = “Not now”,因為以下錯誤:SyntaxError:無法執行“評估” '文檔':字符串 '//button[text() = "Not now"' 不是有效的 XPath 表達式。
這是現在的代碼:
from selenium import webdriver
import time
PATH = "C:\Program Files (x86)\chromedriver.exe"
numeleUsername = input("username: ")
parolaPassword = input("password: ")
driver = webdriver.Chrome(PATH)
driver.get("https://instagram.com/")
time.sleep(2)
driver.find_element_by_xpath("//button[text()='Accept']").click()
username = driver.find_element_by_xpath('//input[@name="username"]')
password = driver.find_element_by_xpath('//input[@name="password"]')
username.click()
username.send_keys(numeleUsername)
password.click()
password.send_keys(parolaPassword)
driver.find_element_by_xpath('//button[@type = "submit"]').click()
time.sleep(1)
driver.find_element_by_xpath('//button[text() = "Not now"').click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//button[text() = "Not Now"]'))).click()
只需等待並單擊它不是現在而不是現在順便說一句的元素。
進口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
您忘記了右方括號。
//button[text() = "Not now"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.