【发布时间】:2021-06-20 12:40:00
【问题描述】:
我想做一个 Instagram 机器人,我还处于起步阶段。 由于这个错误,Selenium 不想点击“Not Now”按钮:
"selenium.common.exceptions.InvalidSelectorException: 消息:无效选择器:由于以下错误,无法使用 xpath 表达式 //button[text() = "Not now" 定位元素: SyntaxError: 无法对 'Document' 执行 'evaluate': 字符串 '//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()
【问题讨论】: