python - 无法在 Python 中使用 Selenium webdriver 登录 Quora

标签 python python-2.7 selenium selenium-webdriver quora

我正在使用 Python 中的 Selenium 模块登录 Quora。它适用于 Facebook,但在 Quora 上尝试时,send_keys('my_email') 行出现错误:

我正在使用以下脚本。

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

driver = webdriver.Firefox()
driver.get('http://www.quora.com/')
time.sleep(60)

username = driver.find_element_by_name('email')
time.sleep(60)
username.send_keys('my_email')
time.sleep(60)

password = driver.find_element_by_name('password')
time.sleep(60)
password.send_keys('my_password')
time.sleep(60)

password.send_keys(Keys.RETURN)

driver.close

sleep 时间在这里不是问题,因为我尝试使用 Python shell 逐行执行脚本。

错误:

Traceback (most recent call last): File "", line 1, in password.send_keys('my_password') File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 293, in send_keys self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing}) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 370, in _execute return self._parent.execute(command, params) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute self.error_handler.check_response(response) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 164, in check_response raise exception_class(message, screen, stacktrace) ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace: at fxdriver.preconditions.visible (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:8791:5) at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11438:1) at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11455:11) at DelayedCommand.prototype.executeInternal_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11460:7) at DelayedCommand.prototype.execute/< (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11402:5)

最佳答案

问题是 name="email" 有多个输入。

您需要“常规登录”部分中的那个:

form = driver.find_element_by_class_name('regular_login')
username = form.find_element_by_name('email')
username.send_keys('my_email')

password = form.find_element_by_name('password')
password.send_keys('my_password')

关于python - 无法在 Python 中使用 Selenium webdriver 登录 Quora,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25569426/

相关文章:

python - 生成xml的最佳方法?

python - SymPy 1.0 中的集成错误

selenium - 如何使用selenium删除文本字段中的默认值?

python - 在 Confluence API 中保留新行

python - 在 Linux 上使用 headless Chrome 访问拒绝页面,而有头 Chrome 通过 Python 使用 Selenium 在 Windows 上运行

Python selenium 进入#document

python - 帮助旋转 xy 像素坐标,不确定我的功能

Python导入错误: No module named cv

python - Heroku 部署错误 : No matching distribution found for en-core-web-sm

python-2.7 - 如何为嵌入 IPython Interactive Shell 的 Python 应用程序编写单元测试