Forums

Selenium firefox works on my computer but does not work on pythonanywhere

Hi everyone, I got this error when I try to run selenium firefox on Pythonanywhere:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"class name","selector":"iconfont.icon-qrcode"}
Stacktrace:
    at FirefoxDriver.findElementInternal_ (file:///tmp/tmp5xfowfyp/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
    at FirefoxDriver.findElement (file:///tmp/tmp5xfowfyp/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
    at DelayedCommand.executeInternal_/h (file:///tmp/tmp5xfowfyp/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.executeInternal_ (file:///tmp/tmp5xfowfyp/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.execute/< (file:///tmp/tmp5xfowfyp/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)

But when I run on my windows 10 machine its completely fine and smooth. May I know why? The version of firefox on my machine is 76.0.1(64-bit)

[edit by admin: formatting]

The version of Firefox we have installed is pretty old, for compatibility with older PythonAnywhere accounts. Your best bet is to use Chrome instead, as we have a more recent version of that installed. You need a new beta feature to use it, but I've activated that for your account, so you just need to upgrade Selenium for your account -- for example, if you're using Python 3.7, run this in Bash:

pip3.7 install --user --upgrade selenium

...and then you can run Selenium with Chrome using code like this:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)

try:
    browser.get("https://www.google.com")
    print("Page title was '{}'".format(browser.title))

finally:
    browser.quit()

Thank you, now I have a problem with Chrome Driver. May I know which directory should I place it? I placed it under /home/username directory but it doesnt seem to work.

If you put it in /home/linhuaian3/.local/bin then it should work fine. You'll need version 2.42.591071, which is the one to match our installed Chromium.

Alternatively, we could update your account to our most recent system image, which has Chromedriver pre-installed, but this would update the pre-installed Python packages and also upgrade the point releases of Python -- for example, 3.7.0 to 3.7.5. This is generally a good thing, but because of the changes to the point releases of Python, any virtualenvs you have might break -- and if you're not using virtualenvs, the pre-installed Python modules will be upgraded so that might break any code you have that relies on the old installed versions.

If you're happy for us to switch you over despite that, then let us know.

Yes please update for me!Thank you

No problem. I have updated your account.

Sorry but there seem to be a lot of problem for me.

My code is as follow:

from selenium import webdriver 
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)

def test():
    try:
        browser.get("https://www.google.com")
        return "Page title was '{}'".format(browser.title)
    finally:
        browser.quit()

test()

pretty much copy pasted, but i get this error:

(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.4.0-1100-aws x86_64)

[edit by admin: formatting]

Sorry, Glenn should have mentioned -- you need to start a fresh console to run code with the updated system image. Could you do that and try again?

Could you activate the beta feature for my account as well?

No problem. I have enabled it for your account.

from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--headless") chrome_options.add_argument("--disable-gpu") browser = webdriver.Chrome(options=chrome_options)

try: browser.get("https://www.google.com") print("Page title was '{}'".format(browser.title))

finally: browser.quit()

error

File "/home/botguy/test.py", line 5, in <module> browser = webdriver.Chrome(options=chrome_options) TypeError: init() got an unexpected keyword argument 'options'

I have updated your account so you it will use the new virtualisation system.

Could you activate the beta feature for my account as well?Thanks.

Sure, @means, it's done for you.

@pafk Thank you very much for your help.

No problem, glad we could help.

hi i have upgrade my account from pyvirtualdisplay import Display from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.common.exceptions import TimeoutException from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options import time

timeout = 40 with Display(): # we can now start Firefox and it will run inside the virtual display driver = webdriver.Firefox()

try: driver.get("https://kite.zerodha.com/") print(driver.title) login = driver.find_element_by_css_selector("button[type=submit]" ) login.click() print(driver.title) finally: driver.quit()

still i am not able to load page and am i geting error

Problem loading page Traceback (most recent call last): File "/home/ishanpatilsvss/demosele.py", line 23, in <module> login = driver.find_element_by_css_selector("button[type=submit]" ) File "/home/ishanpatilsvss/.virtualenvs/myvirtualenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 437, in find_element_by_css_selector return self.find_element(by=By.CSS_SELECTOR, value=css_selector) File "/home/ishanpatilsvss/.virtualenvs/myvirtualenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 752, in find_element 'value': value})['value'] File "/home/ishanpatilsvss/.virtualenvs/myvirtualenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute self.error_handler.check_response(response) File "/home/ishanpatilsvss/.virtualenvs/myvirtualenv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace)

if i use facebook.com still not able to locate any element on selenium

can you help what going wrong

@ishanpatilsvss Looks like we enabled features allowing you to use headless Chrome (you asked for that in another topic)

hi

still i am geting error for headless chrome

Traceback (most recent call last): File "demosele.py", line 64, in <module> browser = webdriver.Chrome(options=chrome_options) TypeError: init() got an unexpected keyword argument 'options'

    from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)

try:
    browser.get("https://www.google.com")
    print("Page title was '{}'".format(browser.title))

finally:
    browser.quit()

chrome_options

To use Chrome, you'll need to upgrade Selenium for your account -- for example, if you're using Python 3.7, run this in Bash:

pip3.7 install --user --upgrade selenium

I went through the process of

pip3.7 install --user --upgrade selenium

and now with

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
driver = webdriver.Chrome(options=chrome_options)

I get the error selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home. Could you please update my account in order to have chromedriver pre-installed?

You have pre-installed chromedriver on your account. Did you do anything to your PATH?

can you update my account for this to work?

@puddingman You already have everything enabled. You need to upgrade selenium if you want to use it. Take a look at post above

Could you update the beta feature to my account too please?

@puddingman You already have everything enabled. You need to upgrade selenium if you want to use it.

I have already upgraded selenium in bash but am still getting similar errors

Namely the error

TypeError: init() got an unexpected keyword argument 'options'

Make sure that you've upgraded selenium in the version of Python that you're using to run your code. If you upgrade selenium in Python 2.7 and then run your code with 3.6, then you'll still be using the old version in your code.

Hi, I'm also getting a similar issue here, with my firefox being too old for the Selenium I'm using. Could you help me with activating the beta feature for my account, so I can use chrome? Btw, I tried running chrome from my cmd and it says command not found, is chrome installed by default?

Hi, I'm also getting a similar issue here, with my firefox being too old for the Selenium I'm using. Could you help me with activating the beta feature for my account, so I can use chrome? Btw, I tried running chrome from my cmd and it says command not found, is chrome installed by default?

It is already enabled for your account. See https://help.pythonanywhere.com/pages/selenium/ about how to use Chrome in Selenium on PythonAnywhere.

Is Firefox browser supported for selenium on Pythonanywhere now? I need to switch to Firefox in the interim while getting the issue with Chrome resolved.

PS: I have raised an issue in another about Chrome browser crashing with the error below

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

I believe we already answered you here. We recommend using Chrome, we can't guarantee Firefox would work.