How to specify "binary" path for remote chromedriver in codeception? - selenium-webdriver

I'm trying to use a remote chromedriver with codeception. I'm currently able to connect to the chromedriver, because if I don't start it, I get a different error (after a long timeout). However, the chromedriver isn't able to start chrome on that windows VM because it's not installed in the path it's searching it for. I tried to override it but can't find the way to setup codeception for that options.
Here's what I tried in my acceptance.suite.yml:
WebDriver:
host: 10.0.15.15
port: 9515
url: 'http://www.box.dev'
browser: 'chrome'
capabilities:
binary: "C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe"
I tried a couple variations over the binary format with \ \ \\ \\ and /. Chrome just don't show up... There isn't much "output" from the chromedriver so I'm going a little bit blind on that...

The chromedriver should run on the host system. You have to start selenium with an option, which says selenium where the chromedriver.exe is located.
java -jar selenium-server-standalone-2.41.0.jar -role node -hub http://www.box.dev:9515/register/grid Dwebdriver.chrome.driver="C:/Users/me/Downloads/chromedriver.exe"
Then you only need to say in your codeception configuration, that you want to use the browser chrome (it should be installed there).

The acceptance.suite.yml that works for me on Windows looks like.
capabilities:
chromeOptions:
args: ["disable-infobars", "headless","disable-gpu", "window-size=1920x1080"]
binary: "C:/Users/***/chrome.exe"

Related

Robot Framework Open Browser and Create WebDriver not working after Updates [duplicate]

Recently I switched computers and since then I can't launch chrome with selenium. I've also tried Firefox but the browser instance just doesn't launch.
from selenium import webdriver
d = webdriver.Chrome('/home/PycharmProjects/chromedriver')
d.get('https://www.google.nl/')
i get the following error:
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 /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)
i have the latest chrome version and chromedriver installed
EDIT:
After trying #b0sss solution i am getting the following error.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)
Try to download HERE and use this latest chrome driver version:
https://sites.google.com/chromium.org/driver/
Try this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
This error message...
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 /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the Chrome browser is not installed at the default location within your system.
The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Solution
In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:
Python Solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\path\\to\\chrome.exe" #chrome binary location specified here
options.add_argument("--start-maximized") #open Browser in maximized mode
options.add_argument("--no-sandbox") #bypass OS security model
options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
Java Solution:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); //chrome binary location specified here
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.com/");
hope this helps someone. this worked for me on Ubuntu 18.10
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()
I encountered the exact problem running on docker container (in build environment). After ssh into the container, I tried running the test manually and still encountered
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome-stable is
no longer running, so ChromeDriver is assuming that Chrome has crashed.)
When I tried running chrome locally /usr/bin/google-chrome-stable, error message
Running as root without --no-sandbox is not supported
I checked my ChromeOptions and it was missing --no-sandbox, which is why it couldn't spawn chrome.
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)
I had a similar issue, and discovered that option arguments must be in a certain order. I am only aware of the two arguments that were required to get this working on my Ubuntu 18 machine. This sample code worked on my end:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')
For RobotFramework
I solved it! using --no-sandbox
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument test-type
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
Instead of
Open Browser about:blank headlesschrome
Open Browser about:blank chrome
Assuming that you already downloaded chromeDriver, this error is also occurs when already multiple chrome tabs are open.
If you close all tabs and run again, the error should clear up.
in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:
opts.set_headless(True)
A simple solution that no one else has said but worked for me was not running without sudo or not as root.
The solutions that every body provide here is good for Clear the face of the issue but
All you need to solve this problem is that You have to run The App on non-root user
on linux.
According to this post
https://github.com/paralelo14/google_explorer/issues/2#issuecomment-246476321
I had the same problem but it was solved just by reinstalling chrome again with the commands below:
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb
This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.
Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.
It solved the issue I was having; not elegantly but it works.
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
try:
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
except WebDriverException as e:
print("\nChrome crashed on launch:")
print(e)
print("Trying again in 10 seconds..")
sleep(10)
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
print("Success!\n")
except Exception as e:
raise Exception(e)
I came across this error on linux environment. If not using headless then you will need
from sys import platform
if platform != 'win32':
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Faced with this issue trying to run/debug Python Selenium script inside WSL2 using Pycharm debugger.
First solution was to use --headless mode, but I prefer to have Chrome GUI during the debug process.
In the system terminal outside Pycharm debugger Chrome GUI worked nice with DISPLAY env variable set this way (followed guide here):
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
Unfortunately ~/.bashrc is not running in Pycharm during the debug, export is not working.
The way I've got Chrome GUI worked from Pycharm debugger: run echo $DISPLAY in WSL2, paste ip (you've got something similar to this) 172.18.144.1:0 into Pycharm Debug Configuration > Environment Variables:
Just do not run the script as the root user (in my case).
i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.
i faced the same problem but i solved it by moving the chromedriver to this path
'/opt/google/chrome/'
and this code works correctly
from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')
In my case, chrome was broken. following two lines fixed the issue,
apt -y update; apt -y upgrade; apt -y dist-upgrade
apt --fix-broken install
Fixed it buy killing all the chrome processeses running in the remote server before running my script.
That may explain why some answers that recommend you run your script as root works.
$ pkill -9 chrome
$ ./my_script.py
Maybe when you where developing in local, you used options.headless=False in order to see what is the browser doing but you forgot to change it to True in the vm.
For me, the root issue was that the google-chrome/chromedriver version were not compatible with the Selenium version.
Seleniumn and Chrome were working fine until a few days ago and I started getting this missing DevToolsActivePort issue. After trying all sorts of solutions on this thread, it finally occurred to me that the Chrome version might not be compatible with the Selenium version.
Versions at the time of the initial error:
# Below combo does NOT work
Python 3.7.3
selenium==3.141.0
Google Chrome 110.0.5481.77
ChromeDriver 110.0.5481.77
I then downgraded Chrome and ChromeDriver to 109.0.5414.74 but still faced the same error. I checked the versions on a different machine and saw that this combo worked:
# Below combo works
Python 3.7.6
selenium==3.141.0
Google Chrome 80.0.3987.100
ChromeDriver 80.0.3987.16
However, I wasn't able to find a download for Google Chrome V80. This comment had a download to V97 so that's the version I went with. There might be higher versions of Google Chrome that do work but after spending so many days fixing this, I was eager to move onto something else.
sudo apt-get purge google-chrome-stable
sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo dpkg -i google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo apt-mark hold google-chrome-stable
wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip chromedriver -d /usr/local/bin
After that, my Selenium calls were able to work again. The final version combo:
# Below combo works
Python 3.7.3
selenium==3.141.0
ChromeDriver 97.0.4692.71
Google Chrome 97.0.4692.71
Make sure that both the chromedriver and google-chrome executable have execute permissions
sudo chmod -x "/usr/bin/chromedriver"
sudo chmod -x "/usr/bin/google-chrome"

OperaDriver for Selenium remains stuck when launching tests

I am using TestNG to run automated tests using a Selenium Java client. The tests are running fine on chrome and firefox but when I try to run the same on opera, I end up seeing tests timing out on the following console message:
Starting OperaDriver 2.35 (ee0117ea0f7f76009fd2aa3dd6b6164205de32b5) on port 27234
Only local connections are allowed.
org.openqa.selenium.WebDriverException:
unknown error: Opera failed to start: exited abnormally
(Driver info: OperaDriver=2.35 (ee0117ea0f7f76009fd2aa3dd6b6164205de32b5),platform=Linux 4.13.0-38-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Environment
Ubuntu 16.04LTS
JDK 10
Selenium 3.11.0
OperaDriver 2.35(downloaded from here)
Code
OperaOptions options = new OperaOptions();
options.setBinary("operadriver");
testDriver = new OperaDriver(options);
I am trying to understand what went wrong here.
Many in the community seem to get the same error when trying to get opera running with selenium and opera driver. I also tested this with your versions and get the same output, although the other browsers are working just fine.
Opera does not seem to put a lot of resources in making this work. Check out this link for some more information, it is actually a slightly different issue, but still there are some background informations there.
The suggested hack is to run opera through an appropriate version of the chromedriver. I also got opera running with selenium that way some time ago (therefore other versions), but I did not yet test this with your configuration.
Update
I managed to get the following configuration work:
Ubuntu 16.04
Java 1.8
Selenium 3.11.0
Operadriver 2.30
Opera 48.0.2685.52
by using the chrome hack and passing the operadriver as the "chrome"driver

PhantomJS register with Selenium Grid

I need assistance on registering PhantomJS with Selenium Grid. Based on some approaches I've seen online I implemented it this way:
Grid register
java -jar selenium-server-standalone-3.0.0-beta2.jar -role hub -port 4444
PhantomJS
phantomjs.exe --webdriver=5555--webdriver-selenium-grid-hub=http://127.0.0.1:4444
both cmd started fine but phantomjs is not registered to the grid
As far as I know, you don't need Selenium to run the test against phantomjs in webdriver mode.
I don't know wich language and framework are you using. But In behat/mink/phantomjs:
Console:
phantomjs --webdriver=8643
And in your behat.yml:
sessions:
"Name_of _your_session":
selenium2:
wd_host: "http://localhost:8643/wd/hub"
The important part here is: wd_host: "http://localhost:8643/wd/hub"
That I'm sure that you can adapt to whatever your system is. You can run the phantomjs from another server and use it only by modifying the IP: "http://XXX.XXX.XXX.XXX:8643/wd/hub"
But you don't need to run the selenium server.

Launch chrome browser

I am trying to launch chrome browser (version 26.0) using webdriver.
I am getting the following error message.
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver.
at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:69)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
at googleSearch.main(googleSearch.java:13)
Code I used:
driver = new ChromeDriver();
driver.navigate().to("http://www.google.com/");
I use mac 10.8.2.
For this to work, you need to:
Install Chrome
Install Chrome Web Driver
Make sure you have the chrome web driver in you path, for example on Windows something pointing to chromedriver2_win32_0.8. You can put that in your path by either: (a) Modifying your windows path environment variable, or; (b) adding the following to your java command line options:
-Dwebdriver.chrome.driver='/path/to/driver'
In case of using selenium grid
-Dwebdriver.chrome.driver='/path/to/driver'
has to be added while creating a node from command line.
1) In case of using selenium without GRID:
System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver");
driver = new ChromeDriver();
does the job.
2) In case of using selenium with GRID:
System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver");
driver = new ChromeDriver();
And from command line, while creating a node for chrome browser one needs to pass
-Dwebdriver.chrome.driver='/absolute/path/to/chromedriver'
The above two changes did the job for me, apart from this I was getting this libnss3.so not found error which I solved by creating a symlink of libnss3.so present in /usr/lib/x86_64-linux-gnu/ folder to /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libnss3.so /usr/lib/libnss3.so
PS: Also make sure that you are using 64bit OR 32bit version of chrome driver as per your system.
For chrome to work with selenium-webdriver you need to have not only a working chrome browser installed, but also the chromedriver executable. Note that these are TWO different executable files that both need to be specified.
change the permission of file and then run your code again.
Open command prompt and navigate to directory where your chrome exe exists and write
chmod 777 filename
Hope it will solve your problem.

Remote debugging with XDebug and PHPStorm

First things first:
Server is an Apache running on Debian in a VMPlayer
Host is Windows 7
Debugging-Server is XDebug
Files are directly accessible via a shared folder
Important: XDebug is properly configured on Apache and my Win7 firewall as well. I know that b/c I can debug using Eclipse.
So what I am failing at seems to be the basic configuration of PHPStorm.
Let me give you some more details:
IP of Server: 192.168.56.128
IP of my host: 192.168.56.1
the file that I want to debug is index.php:
location on my Win7 host: C:\dev\sf\Symfony\
location on Debian: \mnt\hgfs\sf\Symfony\
URL: 192.168.56.128/Symfony/index.php
No matter what I fiddle together ... I get weired error messages like "Waiting for connection from JetBrains PhpStorm..." or PHPStorm asks me for Mozillas profile.ini, even though I configured Chrome as Default in Web Browsers.
So I will just set up a new project and hopefully someone tells me what is wrong with my configuration.
Run / Edit configurations / Defaults / PHP Remote Debugging:
Server: "Debian"
IDE key: -
Break at first line: yes
Servers:
Name: "Debian"
Host: 192.168.56.128
Port: 80
Debugger: Xdebug
use path mappings: yes
one path mapping configured:
C:\dev\sf\Symfony => /mnt/hgfs/sf/Symfony (also tried /Symfony - b/c PHPStorm shouldn't care about anything above /Symfony !?)
Run / Edit configurations / Defaults / PHP Web Application:
Server: "Debian"
Start URL: /Symfony
Browser: Chrome
Break on first line: yes
Now I choose: Run / Debug ... / 1.index.php
And I get asked for: Mozilla's profile.ini ... but I can't find it
Where is it ... ?
I already got so far that PHPStorm started Chrome. But maybe I first sort this out. So how can I get Firefox up and running? I also use Firefox with Eclipse ... no questions asked for a profile.ini.
Okay, there are three things I'd like to share with you. It's not the full recipe but the key ingredients that were first confusing me are:
The important sections to configure are "Servers" and "PHP Remote Debugging".
To configure "PHP Remote Debugging" you have to first add a new dataset using the [+] in the top left corner. The panel you get from just clicking on the "PHP R D"-button just keeps the default settings!
Absolute path regarding the VM actually means the absolute path starting from root (\mnt\hgfs\sf\Symfony). This was confusing to me cause I am still not sure why PhpStorm cares about directory levels above the shared folder. but it does.
If you are still having problems, there are two blog posts by the makers on how to set things up correctly.
First should work in most cases and requires zero-configuration other than a working xdebug install
Second details all of the configuration settings in detail
To 'see' the profile.ini in the PHP Storm 'Select File' Dialog simply rightclick inside of it and choose 'Show hidden files' then (in WIn7) move to C:\Users\YOURUSERNAME\AppData\Roaming\Mozilla\Firefox or the equivalent in your OS
Ensure that remote debugging is enabled in php.ini
xdebug.remote_enable = 1
Your server "192.168.56.128" should be in PHP-> Servers
Add PHP Web Application Debug Configuration, and use added server
Set a breakpoint and start debugging using this configuration

Resources