简体   繁体   English

无法使用Python中的Selenium webdriver登录Quora

[英]Unable to login to Quora using Selenium webdriver in Python

I am using a Selenium module in Python to log into Quora. 我在Python中使用Selenium模块登录Quora。 It works fine for Facebook, but I am getting an error on the send_keys('my_email') line while trying it on Quora: 它适用于Facebook,但在Quora上尝试时,我在send_keys('my_email')行上收到错误:

I am using the following script. 我使用以下脚本。

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 time is not a problem here, because I tried executing a script line by line using the Python shell. 睡眠时间在这里不是问题,因为我尝试使用Python shell逐行执行脚本。

Error: 错误:

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' ; 回溯(最近一次调用最后一次):文件“”,第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”,第370行,在_execute返回self ._parent.execute(command,params)文件“C:\\ Python27 \\ lib \\ site-packages \\ selenium \\ webdriver \\ remote \\ webdriver.py”,第173行,执行self.error_handler.check_response(response)文件“C: \\ Python27 \\ lib \\ site-packages \\ selenium \\ webdriver \\ remote \\ errorhandler.py“,第164行,在check_response中引发exception_class(消息,屏幕,堆栈跟踪)ElementNotVisibleException:消息:u'Element当前不可见,因此可能不是与'互动'; 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) Stacktrace:在DelayedCommand的fxdriver.preconditions.visible(文件:/// c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:8791:5)。在delayededCommand.prototype.executeInternal_ / h中的prototype.checkPreconditions_(文件:/// c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11438:1) (文件:/// 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 / <(file:/// c: /users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver@googlecode.com/components/command_processor.js:11402:5)

The problem is that there are multiple inputs with name="email" . 问题是有多个输入, 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')

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

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