如何解决无法使用硒使用python在网页上进行搜索
我正在运行以下脚本来搜索此网页上的图书:
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。