我在Python中使用Selenium模塊登錄Quora。它適用於Facebook,但我在send_keys('my_email')
線路上嘗試使用Quora時出現錯誤:無法使用Python中的Selenium webdriver登錄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逐行執行腳本。
錯誤:
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/[email protected]/components/command_processor.js:8791:5) at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/[email protected]/components/command_processor.js:11438:1) at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/[email protected]/components/command_processor.js:11455:11) at DelayedCommand.prototype.executeInternal_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/[email protected]/components/command_processor.js:11460:7) at DelayedCommand.prototype.execute/< (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/[email protected]/components/command_processor.js:11402:5)
你得到了什麼錯誤? – 2014-08-29 13:51:55
請在問題中包含完整的回溯。 – alecxe 2014-08-29 13:53:56