Include Selenium/Firefox in Azure Function without Docker [duplicate] - python

Server: Raspberry Pi 3
OS: Dietpi - version 159
Geckodriver version: 0.22 for arm
Firefox version: 52.9.0
Python version: 3.5
Selenium version: 3.14.1
Gecko is executable, and is located in /usr/local/bin/
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
import time
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options)
print('Need your login credential')
username = input('What is your username?:\n')
password = input('What is your password?:\n')
...
...
Output:
root#RPi3:~# python3.5 ITE-bot.py
Traceback (most recent call last):
File "ITE-bot.py", line 12, in <module>
driver = webdriver.Firefox(firefox_options=options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
Any idea what is wrong? I've tried google without luck.

If you are running Firefox on a system with no display, make sure you use headless mode.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Also, make sure you have compatible versions of Firefox, Selenium, and Geckodriver:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html

Thumb rule
A common cause for Browsers to crash during startup is running WebDriver initiated Browsers as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Browser as a regular user instead.
This error message...
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Firefox Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Your GeckoDriver version is 0.22.0.
Release Notes of GeckoDriver v0.21.0 (2018-06-15) clearly mentions the following:
Firefox 57 (and greater)
Selenium 3.11 (and greater)
Your Firefox version is 52.9.0.
So there is a clear mismatch between GeckoDriver v0.22.0 and the Firefox Browser v57
Solution
Upgrade GeckoDriver to GeckoDriver v0.22.0 level.
GeckoDriver is present in the specified location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v62.0.2 levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Execute your Selenium Test as a non-root user.
GeckoDriver, Selenium and Firefox Browser compatibility chart

I was on headless mode, using correct versions of everything, and the only way to get out of this error message was not to execute the selenium test as root

Yes checked Start Xvfb before the build can fix the problem, but if you have a job like a pipeline or multibranch pipeline this option is not visible. In the node of your Selenium grid that you go to execute the test you need:
1- Install Xvfb: apt install xvfb
2- Execute Xvfb: /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"
3- Rerun your node, for example: java -jar selenium.jar -role node -hub http://#.#.#.#:4444/grid/register -capabilities browserName=firefox,plataform=linux -host #.#.#.# -port 1991

This solution worked for me
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

As there can be many different underlying causes for this error it is best to find the root cause setting selenium to use debug level logging. In my case, for Ruby with capybara I needed to set: Selenium::WebDriver.logger.level = :debug. And voilĂ , running the same spec I could see in the logs that a dependency was missing, in my case:
libdbus-glib-1.so.2: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
After installing it all worked fine.

I used:
VS Code
Linunx/Ubuntu:18.10
Nightwatch.js
My problem was that I tried to run Nightwatch (which automatically starts GeckoDriver) from the VS Code terminal.

I had the same problem, and realized that the real problem was some firefox dependencies not being installed inside the docker container I was testing in.
Try to initiate firefox and check if it returns an error.

As Nico and jay have stated you need to check the logs to see the details of the error. As you might use different systems, you can specify the path where the log is stored (i.e. "/tmp/geckodriver.log").
from selenium import webdriver
firefox_options = webdriver.firefox.webdriver.Options()
driver = webdriver.Firefox(log_path="/tmp/geckodriver.log",
options=firefox_options)
In my particular case, what the log said was:
Error: no DISPLAY environment variable specified
That was resolved adding in the options the headless mode before starting the driver. With the line:
firefox_options.set_headless()

I was able to fix this by running my tests with Xvfb. I was running them on a remote server.
I was using Jenkins so I checked the box that looked like this:
Credit to https://www.obeythetestinggoat.com/book/chapter_CI.html

in my case, I was running test cases as root
geckodriver.log
1576076416677 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenCbl2e"
Running Firefox as root in a regular user's session is not supported. ($HOME is /home/seluser which is owned by seluser.)
1576077143004 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile7wpSQ7"
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: telemetry
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1576077145372 Marionette INFO Listening on port 35571
1576077145423 Marionette WARN TLS certificate errors will be ignored for this session
1576077200207 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenhoHlr"
Running Firefox as root in a regular user's session is not supported. ($HOME is /home/seluser which is owned by seluser.)
i could get around by
cd /home
chown -R root seluser
i woundnt say its correct but it got my job done

Related

Got permission denied for chromedriver with Jenkins

I got tests who run on a raspberry with jenkins and Selenium and it work fine.
I got an industrial computer with Ubuntu on it. I have tests who work with command line. But when I launch it with jenkins either by being the jenkins user or by the Jenkins page it does not work.
To simplify in maximum to know where the issue came from, I made a minimum Selenium test which is the following:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options()
options.add_argument('--disable-gpu')
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--headless")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--silent")
options.add_argument("--allow-running-insecure-content")
chromedriver_service = Service("/lib/chromium-browser/chromedriver")
driver = webdriver.Chrome(options=options)
driver.get('https://www.google.com')
driver.close()
And I Got this error:
Traceback (most recent call last):
File "/home/swof/DPASS_Automation/test.py", line 18, in <module>
driver = webdriver.Chrome(options=options)
File "/home/swof/DPASS_Automation/.venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/swof/DPASS_Automation/.venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/swof/DPASS_Automation/.venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
When I launch this test by being the main user no error.
I use python3.9 and a venv to have less issue between different user and that works well on the RPi.
I try different thing:
I add Jenkins to the sudo user by editing /etc/sudoers and add jenkins ALL= (ALL) NOPASSWD: ALL at the end of the file
I gave all right to the folder where my project by using chmod -R 777 /folder
Even if I use a venv I install Selenium with sudo pip install Selenium
When I use Python shell I can import Selenium without issue, it crash only here: driver = webdriver.Chrome (options=options)
I try to uninstall and install jenkins
I think it must be with chromium-browser because I got this error when I try to launch it by being the Jenkins user with chromium-browser:
WARNING: cannot start document portal: dial unix /run/user/1000/bus: connect permission denied
/user.slice/user-1000.slice/user#1000.service/app.slice/app-org.gnome.Terminal.slice/vte-spawn-99fb6268-be1d-42e8-8b6b-5267c428ebf4.scope is not a snap cgroup
A colleague of mine found a solution.
To sum up he change the home directory of Jenkins.
He creates new directory in /home. Copy all the file from /var/lib/Jenkins to this new directory. He gives access to this directory to Jenkins. Finally, he changes the home location in /etc/default/Jenkins.
It is this tutorial he uses: https://dzone.com/articles/jenkins-02-changing-home-directory

How to resolve Selenium error - chrome not reachable

I am facing this issue; I know this question is already present and I have tried the solutions mentioned hence asking this with my configurations and code. I am getting the following error when Celery tasks try to use Selenium;
[2020-06-12 23:23:04,228: WARNING/ForkPoolWorker-1] Message: unknown error: Chrome failed to start: exited abnormally.
(chrome not reachable)
(The process started from chrome location /opt/python/run/venv/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[2020-06-12 23:23:04,230: ERROR/ForkPoolWorker-1] Task Update All Results[73583ec6-474a-4f20-8d88-d7be0a150642] raised unexpected: NameError("name 'sleep' is not defined",)
Traceback (most recent call last):
File "/opt/python/bundle/42/app/fixtures/models.py", line 1035, in get_flash_result
driver = webdriver.Chrome(options=opts)
File "/opt/python/run/venv/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/opt/python/run/venv/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/opt/python/run/venv/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/opt/python/run/venv/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/opt/python/run/venv/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(chrome not reachable)
(The process started from chrome location /opt/python/run/venv/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
I have a Django app on an EC2 server via Elastic Beanstalk which runs periodic tasks using Celery however when webdriver is set I get the error.
The Celery task calls a class method on my model which contains the selenium code. The error doesn't occur if I run the same code via Django shell or call the method from the admin dashboard - just when the Celery task is running.
the error occurs after the following code;
from selenium import webdriver
from selenium.common.exceptions import TimeoutException, NoSuchElementException, ElementClickInterceptedException, WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
...
opts = Options()
opts.headless = True
opts.add_argument("--no-sandbox")
opts.add_argument("--disable-dev-shm-usage")
opts.add_argument("--remote-debugging-port=9222")
assert opts.headless # Operating in headless mode
driver = webdriver.Chrome(options=opts)
My Django app runs on a virtual environment - /opt/python/run/venv - and chromedriver and chrome are available to it;
/opt/python/run/venv/bin/chromedriver &
/opt/python/run/venv/bin/google-chrome --> /opt/google/chrome/google-chrome
versions;
(venv) [ec2-user#ip-172-31-12-230 ~]$ google-chrome --version && which google-chrome
Google Chrome 83.0.4103.97
/opt/python/run/venv/bin/google-chrome
(venv) [ec2-user#ip-172-31-12-230 ~]$ chromedriver --version && which chromedriver
ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103#{#416})
/opt/python/run/venv/bin/chromedriver
(venv) [ec2-user#ip-172-31-12-230 ~]$ pip list
Package Version
--------------------- ----------
celery 4.4.2
Django 3.0.4
django-celery-beat 2.0.0
selenium 3.141.0
I'm asking this again as my previous question was closed without an answer. It was linked to another question here by moderator and closed, however the link doesn't answer my question as I'm still getting the error. I tried making the following adjustments and validations based on the linked question;
Google Chrome and Chromedriver are up to date
executable path (/opt/python/run/venv/bin/chromedriver) to chromedriver was added to webdriver()
.add_argument('--headless') was moved to be the first option set
google-chrome in venv and /usr/bin are symlinks
binary location option added
tried deleting chrome and chromedriver and reinstalling (a few times)
tried changing options to just '--no-sandbox' and '--disable-dev-shm-usage'
I've tried putting it in a loop and adding a sleep
Celery is not using root user or sudo
I only encounter this error when Celery worker executes tasks, I can run the same code being run by the worker in the django shell or via the admin dashboard and don't receive the error so it feels like this is a celery error and not my selenium options.
I had a similar problem to this. Celery, selenium and Chromedriver all worked fine on my local machine. Selenium and Chromedriver worked fine on my live server.. but when I added celery into the mix things went wrong.
I tried everything in the end I set the users/groups of celery to root and everything worked fine.. so it's a permissions issue.
After much fiddling I gave celery ownership of the google-chrome and google-chrome-stable binaries with:
sudo chown celery:celery /usr/bin/google-chrome
sudo chown celery:celery /usr/bin/google-chrome-stable
I had also previous set the chromedirve file to 755 with:
sudo chmod 755 /your/location/chromdriver
Restarted everything... and it worked.

How to properly use selenium with geckodriver and firefox with python on Ubuntu?

I am trying to use the geckodriver with firefox and selenium on my Ubuntu machine. This is the code I have so far:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
#path where browser is installed
binary = '/usr/bin/firefox'
options = webdriver.FirefoxOptions()
options.binary = binary
options.add_argument('start-maximized')
options.add_argument('--headless')
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
path_to_driver = "/home/andrea/geckodriver"
# run firefox webdriver from executable path
driver = webdriver.Firefox(firefox_options=options, capabilities=cap, executable_path = path_to_driver)
#driver = webdriver.Firefox(capabilities=cap, executable_path = path_to_driver)
driver.get("https://www.amboss.com/us/account/login")
Despite that I am getting the following error:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile.
Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpuigrk9f7 If you specified a log_file in the FirefoxBinary constructor, check it for details.
The firefox version which I work with is:
Mozilla Firefox 68.0.2
Does anyone have any idea as to how I could go about fixing this?
Step1: Install Selenium
Type in Terminal(in Ubuntu) or in Command Prompt(in Windows)
$pip install selenium
Step2: Download Geckodriver
In order to work with Selenium there should be an executable called 'Gecko Driver' installed.
Download Gecko Driver from the following page:
https://github.com/mozilla/geckodriver/releases
Step3: Install Gecko Driver
Latest version for Windows:
https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-win64.zip
Latest version for Ubuntu:
https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
Setup Gecko Driver For Windows:
Extract the zip file and move the geckodiver.exe executable file to any location which is already in Path variable(For Example you can move it to Python path location)
Unless add the path of 'geckodriver.exe' to the Path variable
Setup Gecko Driver For Ubuntu:
Open Terminal
Ctrl+Alt+T
move directory to the location where tar file is downloaded
Usually it will be in Downloads. so type $ cd Downloads
Unzip the tar file
eg:
$sudo tar -xvf filename.tar.gz
In my case it is:
$sudo tar -xvf geckodriver-v0.26.0-linux64.tar.gz
Move the geckodriver executable file to the '/usr/local/bin' location
$sudo mv geckodriver /usr/local/bin/
Move the directory to '/usr/local/bin/'
$cd /usr/local/bin/
Now make executable permission for 'geckodriver' executable file
$sudo chmod +x geckodriver
Now type 'geckodriver' in Terminal
geckodriver
If Gecko Driver is not working still then add its path
$export PATH=$PATH:/usr/local/bin/geckodriver
Now it is ready to work with selenium
Sample Code
Some sample codes are here:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import ui
driver = webdriver.Firefox()
driver.get('https://www.google.com/')
page_url=driver.find_elements_by_xpath("//a[#class='content']")
all_title = driver.find_elements_by_class_name("title")
title = [title.text for title in all_title]
print(title)
This error message...
selenium.common.exceptions.WebDriverException: Message: Can't load the profile.
Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpuigrk9f7 If you specified a log_file in the FirefoxBinary constructor, check it for details.
...implies that there was a mismatch between the GeckoDriver and Firefox version while initiating/spawning a new WebBrowsing Session i.e. Firefox Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using Mozilla Firefox v68.0.2
Your Selenium Client version is is unknown to us.
Your GeckoDriver version is unknown to us.
However as you are using Mozilla Firefox v68.0.2, using GeckoDriver is mandatory and while you use GeckoDriver you can't set the capability marionette as False.
You can find a detailed discussion in How can Geckodriver/Firefox work without Marionette? (running python selenium 3 against FF 53)
Solution
Upgrade Selenium to current levels Version 3.141.59.
Upgrade GeckoDriver to current GeckoDriver v0.24.0 level.
GeckoDriver is present in the specified location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v68.0.2 levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your Test as a non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Outro
GeckoDriver, Selenium and Firefox Browser compatibility chart
If you want to use Firefox with Selenium, you need to import e Firefox Profile. You can use your own Profile through the following steps :
Locate the Firefox Profile directory
You have to specify the absolute path of the Firefox Profile directory when you initiate the webdriver.
from selenium import webdriver
profile = webdriver.FirefoxProfile(*path to your profile*)
driver = webdriver.Firefox(firefox_profile=profile)

Python Gmail auto login script [duplicate]

I have a script which uses selenium for testing. Now even opening a Google page using
driver.get(url) # url = Google homepage url
is giving me below error
driver.get("https://my.gumtree.com/login")
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 245, in get
self.execute(Command.GET, {'url': url})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: missing or invalid 'entry.level'
(Session info: chrome=65.0.3315.3)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.16299 x86_64)
I have Google chrome version 65, Chromedriver 2.35 and selenium 2.53.1
I tried different version combinations(mentioned in below table) as per solutions mentioned in other similar questions but nothing worked.
Selenium Chrome Chromedriver
2.53.0 63 2.33
2.53.1 65(latest) 2.34
3.6.0 2.35(latest)
3.7.0
3.8.0
3.8.1(latest)
EDIT 1: JDK version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
The error says it all :
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: missing or invalid 'entry.level'
Your main issue is the version compatibility among the binaries you are using as follows :
You are using chromedriver=2.29.461591 (which is as per the logs, though you mentioned Chromedriver 2.35 in your question)
Release Notes of chromedriver=2.29.461591 clearly mentions the following :
Supports Chrome v56-58
You are using chrome=65.0.3315.3
Release Notes of chromedriver=2.35 clearly mentions the following :
Supports Chrome v62-64
You are using Selenium Version 2.53.1.
Your JDK version is unknown to us.
Solution
Upgrade JDK to recent levels JDK Version 8 Update 151.
Upgrade ChromeDriver to ChromeDriver v2.35 level.
Keep Chrome to Chrome v64.x levels. (as per ChromeDriver v2.35 release notes)
Upgrade Selenium to current levels Version 3.8.1.
Clean the Project Workspace from your IDE & Rebuild All.
Run CCleaner tool to wipe off all the OS chores.
If your Chrome base version is too old, uninstall Chrome through Revo Uninstaller and install a recent GA Release version of Chrome.
Take a System Reboot.
Execute your Test.
Go to http://chromedriver.chromium.org/downloads
copy the download link according to your OS
wget -N paste_the_link_you_copied
unzip it using below command
unzip chromedriver_linux64.zip
Give the permission by the below command
chmod +x chromedriver
Then follow the below commands, if it says already exists (probabily old version) then go to that path (/usr/local/bin/chromedriver and /usr/bin/chromedriver) and delete chromedriver and run the commands again
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
Hope this helps. Thanks
That error raised beacuse your chrome browser is not compatible with the web driver. If you are using Linux, then simply execute the following command.
sudo apt-get update
Recently I am facing the same problem and take me too much time to figure out what's going on, in my situation facing the problem, I did not close the chrome process after using it, so you should check the process exit or not when you exit the app, this is my last worked Python 3 code demo, hope it will help others:
#staticmethod
def fetch_music_download_url(music_name: str):
chrome_driver_service = Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install())
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--remote-debugging-port=9230")
driver = webdriver.Chrome(service=chrome_driver_service,
options=chrome_options,
executable_path="/usr/local/bin/chromedriver")
try:
driver.maximize_window()
driver.get('http://tool.example.cn/music/?page=audioPage&type=migu&name=' + music_name)
driver.implicitly_wait(5)
driver.find_element(By.CSS_SELECTOR, ".aplayer-list-download.iconfont.icon-xiazai").click()
urls = [a.get_attribute('href') for a in
driver.execute_script('return document.querySelectorAll(".modal-body a[href*=\'http\']")')]
for url in urls:
if "listenSong.do" in url:
logger.info("fetched url:" + url)
FetchMusic.do_save_music_download_url(url)
except Exception as e:
logger.error("scrapy impl error", e)
finally:
driver.stop_client()
driver.close()
driver.quit()
chrome_driver_service.stop()

Selenium WebDriverException: Message: unknown error: cannot determine loading status from unknown error: missing or invalid 'entry.level'

I have a script which uses selenium for testing. Now even opening a Google page using
driver.get(url) # url = Google homepage url
is giving me below error
driver.get("https://my.gumtree.com/login")
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 245, in get
self.execute(Command.GET, {'url': url})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: missing or invalid 'entry.level'
(Session info: chrome=65.0.3315.3)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.16299 x86_64)
I have Google chrome version 65, Chromedriver 2.35 and selenium 2.53.1
I tried different version combinations(mentioned in below table) as per solutions mentioned in other similar questions but nothing worked.
Selenium Chrome Chromedriver
2.53.0 63 2.33
2.53.1 65(latest) 2.34
3.6.0 2.35(latest)
3.7.0
3.8.0
3.8.1(latest)
EDIT 1: JDK version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
The error says it all :
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: missing or invalid 'entry.level'
Your main issue is the version compatibility among the binaries you are using as follows :
You are using chromedriver=2.29.461591 (which is as per the logs, though you mentioned Chromedriver 2.35 in your question)
Release Notes of chromedriver=2.29.461591 clearly mentions the following :
Supports Chrome v56-58
You are using chrome=65.0.3315.3
Release Notes of chromedriver=2.35 clearly mentions the following :
Supports Chrome v62-64
You are using Selenium Version 2.53.1.
Your JDK version is unknown to us.
Solution
Upgrade JDK to recent levels JDK Version 8 Update 151.
Upgrade ChromeDriver to ChromeDriver v2.35 level.
Keep Chrome to Chrome v64.x levels. (as per ChromeDriver v2.35 release notes)
Upgrade Selenium to current levels Version 3.8.1.
Clean the Project Workspace from your IDE & Rebuild All.
Run CCleaner tool to wipe off all the OS chores.
If your Chrome base version is too old, uninstall Chrome through Revo Uninstaller and install a recent GA Release version of Chrome.
Take a System Reboot.
Execute your Test.
Go to http://chromedriver.chromium.org/downloads
copy the download link according to your OS
wget -N paste_the_link_you_copied
unzip it using below command
unzip chromedriver_linux64.zip
Give the permission by the below command
chmod +x chromedriver
Then follow the below commands, if it says already exists (probabily old version) then go to that path (/usr/local/bin/chromedriver and /usr/bin/chromedriver) and delete chromedriver and run the commands again
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
Hope this helps. Thanks
That error raised beacuse your chrome browser is not compatible with the web driver. If you are using Linux, then simply execute the following command.
sudo apt-get update
Recently I am facing the same problem and take me too much time to figure out what's going on, in my situation facing the problem, I did not close the chrome process after using it, so you should check the process exit or not when you exit the app, this is my last worked Python 3 code demo, hope it will help others:
#staticmethod
def fetch_music_download_url(music_name: str):
chrome_driver_service = Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install())
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--remote-debugging-port=9230")
driver = webdriver.Chrome(service=chrome_driver_service,
options=chrome_options,
executable_path="/usr/local/bin/chromedriver")
try:
driver.maximize_window()
driver.get('http://tool.example.cn/music/?page=audioPage&type=migu&name=' + music_name)
driver.implicitly_wait(5)
driver.find_element(By.CSS_SELECTOR, ".aplayer-list-download.iconfont.icon-xiazai").click()
urls = [a.get_attribute('href') for a in
driver.execute_script('return document.querySelectorAll(".modal-body a[href*=\'http\']")')]
for url in urls:
if "listenSong.do" in url:
logger.info("fetched url:" + url)
FetchMusic.do_save_music_download_url(url)
except Exception as e:
logger.error("scrapy impl error", e)
finally:
driver.stop_client()
driver.close()
driver.quit()
chrome_driver_service.stop()

Categories

Resources