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