Selenium WebDriver Firefox connect error for Linux OS - linux

I have tried all solution suggested by Google. But still struggling to below issue. I have setup of PHPUnit-Selenium based automation framework using headless Firefox on RedHat Linux
Selenium Log Error :
Caused by: org.openqa.selenium.WebDriverException: Failed to connect
to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output
follows: Error: no display specified Error: no display specified
So far I tried:
updated version of selenium driver
updated version of firefox
various selenium-firefox combinations using older versions
Xvfb working fine
Please also let me know :
How i can verify firefox on port 7055 ?
Is etc/hosts file can have cause of this issue ?

Related

WebDriverException: unknown error: cannot find Chrome binary error when trying to run webbot using Selenium and ChromeDriver

I'm trying to automate a process using selenium. When I run the code it gives me the error bellow.
WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.22000 x86_64)
I have downloaded the new driver and passed the variable in system variables under path. Can anyone please help me figure this out. I'm a student just starting my tech career.
This question has been asked many times before in similar disguises and the answers have usually advised to match versions. However, i have often struggled to match versions (for various reasons) and this is rather cumbersome when the versions keep changing.
For this reason, I use the ChromeDriverManager() which installs the correct version at each time.
You need to install webdriver-manager:
pip install webdriver-manager
And this is the working code
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
service=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
You can find the docs here:
https://pypi.org/project/webdriver-manager/
This module recognises and has solved a problem for us all:
It’s boring!!! Moreover every time the new version of driver released, you should go and repeat all steps again and again.
I hope it helps.
This error message...
WebDriverException: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.39.562718
...implies that the ChromeDriver was unable to locate the google-chrome executable.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.39
As per this discussion chromedriver=2.39 :
Supports Chrome v66-68
Possibly you are using the latest chrome=99.0
Release Notes of ChromeDriver v99.0.4844.51 clearly mentions the following :
Supports Chrome version 99
So there is a clear mismatch between chromedriver=2.39 and the chrome=99.0
Solution
Ensure that:
Selenium is upgraded to current released Version 4.1.3.
ChromeDriver is updated to current ChromeDriver v99.0 level.
Chrome Browser is updated to current chrome=99.0 (as per chromedriver=99.0.4844.51 release notes).

vscode on Ubuntu is unable to open windows

I'm having issues with vscode on Ubuntu running particular Python code (that seemingly relies on porting or connecting to an external application). The same code will run fine if I execute it directly from an Ubuntu terminal with the same env on the same machine.
Here's a couple of examples.
When I try to initiate vedo.plotter.Plotter() when running from vscode, I get this error:
ERROR: In /work/standalone-x64-build/VTK-source/Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx, line 1223
vtkXOpenGLRenderWindow (0x5587f7b42cf0): bad X server connection. DISPLAY=Aborted (core dumped)
If I run the same code directly in terminal, it runs fine, so this is an issue with the way vscode is configured, but I can't find any answers online. I've played with a few settings in vscode but with no success.
This seems to be an issue on all vscode installations I have running on Ubuntu (in this case 20.04). Here's the vscode info:
Version: 1.51.0
Commit: fcac248b077b55bae4ba5bab613fd6e9156c2f0c
Date: 2020-11-05T18:16:10.374Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 5.4.0-52-generic snap
Similarly, I'm unable to open up browser windows from vscode (for example plotly fig.show() and selenium driver = webdriver.Chrome(chromedriver) won't open browser windows. I get the following error with selenium:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
Again, this works fine direct from the terminal and everything works fine if run from a Windows or Mac installed vscode, so this is specific to this Ubuntu install.
I'd really appreciate any help!
Jonny

Python 3 - selenium on xvfb-run- cannot process extension

I need to automate tasks to extract information from websites using the uBlock plugin with Chrome driver using the selenium module in Python 3.
I am running my code remotely without a GUI on the remote machine - for that I am using xvfb-run to simulate a desktop environment where Chrome launches with a specific window size.
The remote machine has the following Debian operating system:
uname -a
Linux mem 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) x86_64 GNU/Linux
These were the steps I took to configure my environment and code on the remote machine:
1 - To configure my environment, I installed this version of Google Chrome:
google-chrome --version
Google Chrome 86.0.4240.111
2 - Check the versions of Python 3 and selenium I installed:
python --version
Python 3.7.3
pip freeze
selenium==3.141.0
3 - Check the xvfb-run version:
apt-cache policy xvfb
2:1.20.4-1+deb10u1
4 - With these packages configured, I obtained the chromedriver_linux64.zip from this list (the version 86.0.4240.22 below is the most recent one that is the same major version of the installed google-chrome):
https://chromedriver.storage.googleapis.com/index.html
https://chromedriver.storage.googleapis.com/index.html?path=86.0.4240.22/
5 - To be able to use the uBlock extension of Chrome, I needed to install an extension that is able to produce a .crx archive file of other installed extensions.
For this, I used CRX Extractor/Downloader:
https://chrome.google.com/webstore/detail/crx-extractordownloader/ajkhmmldknmfjnmeedkbkkojgobmljda
6 - After using that extension, I got my ublock.crx file to test.
I managed to use the binary in chromedriver_linux64.zip without the extension to launch a Chrome instance and do some basic crawling.
But when I tried to use ublock.crx in my code, I got an exception.
The code was this:
This is the exception produced:
ublock.crx error
selenium.common.exceptions.SessionNotCreatedException: Message: session not
created: cannot process extension #1
from unknown error: cannot unzip
I am launching it from my program like this:
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_extension(ublock_crx_file_path)
driver = webdriver.Chrome(executable_path=driver_path, options=option)
I have made sure the path of ublock_crx_file_path is valid and points to the file I obtained from Chrome.
Hopefully someone can shed light on this?

AttributeError: 'LifoQueue' object has no attribute 'put' selenium webdriver

I have installed selenium and the chrome web driver and made it accessible via the path variable of my operating system (using Linux virtual machine on windows and python3). I run this simple code and get the below error. Any ideas as to what may cause this error?
Thanks in advance!
Selenium version installed:
selenium-3.141.0 urllib3-1.25.8
Chrome driver installed (latest version for chrome browser 80) :
ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987#{#882})
Chrome browser installed :
Google Chrome 80.0.3987.132
Python version :
Python 3.6.9
import selenium
from selenium import webdriver
options = webdriver.chrome.options.Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
chromedriver = '/usr/bin/chromedriver'
print('test0') #is being printed
driver = webdriver.Chrome('/usr/bin/chromedriver',options=options)
print('test') #not being printed
driver.get('http:google.com')
Error message when running the code : The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.
When I try to run google-chrome with (sudo google-chrome) I get this message:
[56:56:0316/235226.650275:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
I tried modifying the google-chrome file in the /usr/bin but it is read-only so the workaround I found online was to add the options '--no-sandbox' in my code above. But hasn't resolved the issue.
Resolved : had a python file named queue in working directory and had to rename it
Solution:
This error "AttributeError: 'LifoQueue' object has no attribute 'put' selenium webdriver" is caused by having in your working directory a file with the name Queue. Rename that.
For this error "The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed."
If you tried all possible solutions and still get issues then if you are using Linux virtual machine that seems to be causing the problem and I suggest to install docker desktop on windows and download a docker image with all the libraries you will be needing to run selenium apps .

Selenium WebDriver: Connection refused (Connection refused)

I'm running npm test on mean.js version 4.2 and it's giving me a "connection refused" error on the protractor e2e tests. I tried updating selenium like this says to. Right now it's version 2.27 and the other Stack Overflow post says 2.24. Did the chrome driver break again?
Running "protractor:e2e" (protractor) task
webdriver-manager path: /Users/tdiddy/meaning42/node_modules/grunt-protractor-runner/node_modules/protractor/bin/webdriver-manager
selenium standalone is up to date.
chromedriver is up to date.
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://192.168.0.30:53658/wd/hub
/Users/tdiddy/meaning42/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/atoms/error.js:108
var template = new Error(this.message);
^
UnknownError: Connection refused (Connection refused)
at new bot.Error (/Users/tdiddy/meaning42/node_modules/grunt-protractor-runner/node_modules/selenium-webdriver/lib/atoms/error.js:108:18)
In this context, to answer your question, I believe chromedriver 2.27 is not used...this is why:
"Selenium standalone server started at http:" means that you have started the selenium standalone server with the local driver provider. When you start Protractor version 4 (grunt-protractor-runner uses Protractor version ^4.0.0) with a local driver provider, the chromedriver used is the version stated in the webdriver-manager's configuration. Just because you download 2.27 does not mean that Protractor will use Protractor 2.27 when launching locally.
There are two ways to use chromedriver 2.27:
You'll need Protractor 5 to use the last downloaded binary when launching a local driver provider. Download chromedriver 2.27 with webdriver-manager update --versions.chrome 2.27 then launch your Protractor test.
Do not use the local driver provider. Download your binaries with webdriver-manager update --versions.chrome 2.27 then launch your selenium standalone server with webdriver-manager start --versions.chrome 2.27. Once you have started that, launch it with seleniumAddress: "http://localhost:4444/wd/hub" in your configuration.
Why you are getting Connection refused could be because the Chrome version you are running at the chromedriver version you are using are not compatible. I would suggest trying a combination of the two suggestions: use a seleniumAddressin your configuration with Protractor 5.0.0. If this combination fails, please feel free to open up an issue.
I was getting this error and updating chromedriver to v2.32 via brew (brew update chromedriver) fixed it for me

Resources