簡體   English   中英

無法使用 selenium 在帶有 python 的網頁上進行此搜索

[英]Can't make this search on a webpage with python using selenium

我正在運行以下腳本來搜索此網頁上的書籍:

from selenium import web-driver
from selenium.webdriver.common.keys import Keys
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

#going to a website
driver.get("https://pacobello.com.br/")

#print the page title
print(driver.title)

search = driver.find_element_by_name("s")
search.send_keys("Saramago")
search.send_keys(Keys.RETURN)

time.sleep(5)

#quit a tab
#driver.close()

#quit the browser
driver.quit()

我收到以下錯誤:

raise exception_class(message, screen, stacktrace)

ElementNotInteractableException: element not interactable
  (Session info: chrome=84.0.4147.125)

有人對此有任何想法嗎?

使用 XPATH 代替:

search = driver.find_element_by_xpath("//input[@type='text']")

因此完整的代碼將是:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time


PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

#going to a website
driver.get("https://pacobello.com.br/")

#print the page title
print(driver.title)

search = driver.find_element_by_xpath("//input[@type='text']")
search.send_keys("Saramago")
search.send_keys(Keys.RETURN)

time.sleep(5)

#quit a tab
#driver.close()

#quit the browser
driver.quit()

安裝 83 版本的 chrome 不是 84

https://chromedriver.chromium.org/downloads

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM