无法在Python中使用Selenium Webdriver登录Quora [英] Unable to login to Quora using Selenium webdriver in Python

查看:128
本文介绍了无法在Python中使用Selenium Webdriver登录Quora的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python中使用Selenium模块登录Quora.它在Facebook上正常工作,但是在Quora上尝试在send_keys('my_email')行上遇到错误:

I am using a Selenium module in Python to log into Quora. It works fine for Facebook, but I am getting an error on the send_keys('my_email') line while trying it on Quora:

我正在使用以下脚本.

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

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

Sleep time is not a problem here, because I tried executing a script line by line using the Python shell.

错误:

回溯(最近一次通话最近):文件",第1行,在 password.send_keys('my_password')文件"C:\ Python27 \ lib \ site-packages \ selenium \ webdriver \ remote \ webelement.py", 第293行,位于send_keys中 self._execute(Command.SEND_KEYS_TO_ELEMENT,{'value':键入})文件 "C:\ Python27 \ lib \ site-packages \ selenium \ webdriver \ remote \ webelement.py", _execute中的第370行 返回self._parent.execute(命令,参数)文件"C:\ Python27 \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py", 第173行,在执行中 self.error_handler.check_response(响应)文件"C:\ Python27 \ lib \ site-packages \ selenium \ webdriver \ remote \ errorhandler.py", 第164行,在check_response中 引发exception_class(消息,屏幕,堆栈跟踪)ElementNotVisibleException:消息:u'Element当前不是 可见的,因此可能不会与之交互";堆栈跟踪: 位于fxdriver.preconditions.visible(file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:8791:5) 在DelayedCommand.prototype.checkPreconditions_中(文件:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11438:1) 在DelayedCommand.prototype.executeInternal_/h(file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11455:11) 在DelayedCommand.prototype.executeInternal_上(file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11460:7) 在DelayedCommand.prototype.execute/< (文件:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11402:5)

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"有多个输入.

您需要常规登录"部分中的一个:

You need the one in the "Regular Login" section:

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中使用Selenium Webdriver登录Quora的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆