繁体   English   中英

我正在尝试让 Selenium 谷歌搜索点击,但它总是给我一个错误

[英]I am trying to make Selenium google search click, but it always gives me an error

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path="Driver\\chromedriver.exe")
driver.implicitly_wait(10)
driver.get("https://www.google.com/")
driver.find_element(By.XPATH, "//button[contains(text(),'No thanks')]").click()
driver.switch_to.frame(driver.find_element(By.XPATH, "//iframe[@name='account']"))
driver.find_element(By.CSS_SELECTOR, "input[title='Search']").send_keys("google")

以上是我正在尝试编写的脚本。 我没有得到没有这样的元素异常粘贴下面的错误消息。

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[contains(text(),'No thanks')]"}
  (Session info: chrome=104.0.5112.81)
Stacktrace:
Backtrace:
    Ordinal0 [0x00E878B3+2193587]
    

我尝试链接“https://www.google.com”。

它只在第一次显示“不,谢谢”按钮。

也许您可以使用“http://www.google.com”进行搜索,并删除以下行。

driver.find_element(By.XPATH, "//button[contains(text(),'No thanks')]").click()

顺便说一句,如果你想搜索 function。 我认为谷歌搜索 API是另一种方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM