在pythoanywhere.com上运行selenium

时间:2018-03-11 18:43:36

标签: python selenium pythonanywhere

我已经编写了一个代码并在我的计算机上运行完美,然后我决定将其移到服务器云上,然后在pythonanywhere.com上创建一个帐户 然后,经过大量的尝试,我明白chromedriver不在那里工作,但只是firefox,没什么大不了的。 然后我做了一些测试并且工作正常,但是当我尝试使用时:

browser.find_element_by_link_text('Log in').click()

不起作用

好吧,我的代码是:`

from pyvirtualdisplay import Display
from selenium import webdriver
from time import sleep



with Display():
    browser = webdriver.Firefox()


    try:
        browser.get('https://www.instagram.com')
        print("get instagram.com ")

        browser.implicitly_wait(60)
        browser.find_element_by_link_text('Log in').click()
        print("click log in")
        sleep(10)

   finally:
        browser.quit()

错误是:

get instagram.com 
Traceback (most recent call last):
 File "/home/fobu36/.virtualenvs/prova_selenium.py", line 16, in <module>
browser.find_element_by_link_text('Log in').click()
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", l
ine 317, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", l
ine 752, in find_element
'value': value})['value']
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", l
ine 236, in execute
self.error_handler.check_response(response)
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/errorhandler.py"
, line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate 
element: {"method":"l
ink text","selector":"Log in"}
Stacktrace:
at FirefoxDriver.findElementInternal_ 
(file:///tmp/tmpbydkaxfk/extensions/fxdriver@googlecode.
com/components/driver-component.js:10770)
at fxdriver.Timer.setTimeout/<.notify 
(file:///tmp/tmpbydkaxfk/extensions/fxdriver@googlecode.
com/components/driver-component.js:625)

似乎无法找到登录按钮,但我确信在本地它正在工作

0 个答案:

没有答案