python-3.x - 无法使用 python-Selenium 单击“提交”按钮

标签 python-3.x google-chrome selenium webautomation

我正在尝试使用 Selenium Web 自动化从 Google 搜索中提取值。

from selenium import webdriver
import time
import os

#open googole.com
driver = webdriver.Chrome()
time.sleep(2)
driver.get("https://www.google.co.in")

#search for bitcoin exchange rates
elem = driver.find_element_by_id("lst-ib")
elem.clear()
time.sleep(2)
elem.send_keys("bitcoin exchange rates")
time.sleep(2)
driver.find_element_by_name("btnK").click()

time.sleep(2)

#Store the value in a variable
rate = driver.find_element_by_xpath('//*[@id="rso"]/div[1]/div/div/div[2]/span[1]')

RateValue = rate.text
TodayDate = time.strftime("%x")

这与 Firefox 浏览器完美配合。但是,当我使用 Chrome 运行它时,出现以下错误:

self.error_handler.check_response(response) File "C:\Users\Alauddeen\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (440, 411). Other element would receive the click: ... (Session info: chrome=62.0.3202.94) (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86)

我在这里缺少什么吗?如有任何帮助,我们将不胜感激。

谢谢!

最佳答案

btnK 顶部可能有一个搜索建议框,将其隐藏在视线之外,因此无法单击。

使用类似的东西

elem.send_keys(Keys.ENTER)

或者

elem.send_keys(Keys.ESCAPE)

将搜索文本发送到输入以使建议框消失后。

关于python-3.x - 无法使用 python-Selenium 单击“提交”按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47698564/

相关文章:

google-chrome - 在 Chrome 上持续模拟 GPS 位置

javascript - 有没有办法在nightwatch中指定firefox的可执行路径?

javascript - 用于 javascript lzw 压缩的字母字典, "only-use-these-chars"-string

CSS:尝试将图像垂直居中放置在 div 内...Chrome、Safari 问题

java - 将工作表添加到现有的 Excel 文件中

java - java中的Selenium下拉问题

python - 获取当天获取的数据的方法

python - Python 中的 URL 请求失败 - 找不到 SSL 证书

python - Django-Filter:在搜索时动态创建查询集或在搜索之前隐藏查询集

python-3.x - Django静态文件404使用nginx