Trouble in launching of firefox browser using selenium for MAC OS - java

I am using Selenium to test a website in Java and trying to run it in Firefox on a MAC. But when I am trying to execute the code below
Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.example.com/");
I am getting the following runtime exception
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Browser not supported: /Users/sumitghosh/Desktop/*firefox3
(Did you forget to add a *?)
Supported browsers include:
*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom
I have also tried changing the browser to *googlechrome, but the same error was firing!
But when *safari was used it ran successfully.
Since I want the application to run on Windows and MAC also, I was trying for *firefox or *googlechrome to run, but both browsers are giving exceptions both on Windows and MAC!

I have only ever got firefox 3.X to work on MACOSX with selenium.
Try downloading and installing a 3.X version (I got 3.18 to work).

Instead of "*firefox" you can try "*firefox /Apps/Firefox/firefox.exe" or any other absolute path to the file firefox.exe which works for your computer.

Related

DevToolsActivePort file doesn't exist - chromedriver [duplicate]

I am trying to launch chrome with an URL, the browser launches and it does nothing after that.
I am seeing the below error after 1 minute:
Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
My configuration:
Chrome : 66
ChromeBrowser : 2.39.56
P.S everything works fine in Firefox
Thumb rule
A common cause for Chrome to crash during startup is running Chrome 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 Chrome as a regular user instead.
This error message...
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your code trials and the versioning information of all the binaries would have given us some hint about what's going wrong.
However as per Add --disable-dev-shm-usage to default launch flags seems adding the argument --disable-dev-shm-usage will temporary solve the issue.
If you desire to initiate/span a new Chrome Browser session you can use the following solution:
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
disable-dev-shm-usage
As per base_switches.cc disable-dev-shm-usage seems to be valid only on Linux OS:
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The /dev/shm partition is too small in certain VM environments, causing
// Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
// work-around this issue (a temporary directory will always be used to create
// anonymous shared memory files).
const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
#endif
In the discussion Add an option to use /tmp instead of /dev/shm David mentions:
I think it would depend on how are /dev/shm and /tmp mounted.
If they are both mounted as tmpfs I'm assuming there won't be any difference.
if for some reason /tmp is not mapped as tmpfs (and I think is mapped as tmpfs by default by systemd), chrome shared memory management always maps files into memory when creating an anonymous shared files, so even in that case shouldn't be much difference. I guess you could force telemetry tests with the flag enabled and see how it goes.
As for why not use by default, it was a pushed back by the shared memory team, I guess it makes sense it should be useing /dev/shm for shared memory by default.
Ultimately all this should be moving to use memfd_create, but I don't think that's going to happen any time soon, since it will require refactoring Chrome memory management significantly.
Reference
You can find a couple of detailed discussions in:
unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd
Outro
Here is the link to the Sandbox story.
I started seeing this problem on Monday 2018-06-04. Our tests run each weekday. It appears that the only thing that changed was the google-chrome version (which had been updated to current) JVM and Selenium were recent versions on Linux box ( Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62, and xvfb-run).
Specifically adding the arguments "--no-sandbox" and "--disable-dev-shm-usage" stopped the error.
I'll look into these issues to find more info about the effect, and other questions as in what triggered google-chrome to update.
ChromeOptions options = new ChromeOptions();
...
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
We were having the same issues on our jenkins slaves (linux machine) and tried all the options above.
The only thing helped is setting the argument
chrome_options.add_argument('--headless')
But when we investigated further, noticed that XVFB screen doesn't started property and thats causing this error. After we fix XVFB screen, it resolved the issue.
I had the same problem in python. The above helped. Here is what I used in python -
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/path/to/your_chrome_driver_dir/chromedriver',chrome_options=chrome_options)
I was facing the same issue recently and after some trial and error it worked for me as well.
MUST BE ON TOP:
options.addArguments("--no-sandbox"); //has to be the very first option
BaseSeleniumTests.java
public abstract class BaseSeleniumTests {
private static final String CHROMEDRIVER_EXE = "chromedriver.exe";
private static final String IEDRIVER_EXE = "IEDriverServer.exe";
private static final String FFDRIVER_EXE = "geckodriver.exe";
protected WebDriver driver;
#Before
public void setUp() {
loadChromeDriver();
}
#After
public void tearDown() {
if (driver != null) {
driver.close();
driver.quit();
}
}
private void loadChromeDriver() {
ClassLoader classLoader = getClass().getClassLoader();
String filePath = classLoader.getResource(CHROMEDRIVER_EXE).getFile();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(filePath))
.build();
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
options.addArguments("--headless");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.merge(capabilities);
this.driver = new ChromeDriver(service, options);
}
}
GoogleSearchPageTraditionalSeleniumTests.java
#RunWith(SpringRunner.class)
#SpringBootTest
public class GoogleSearchPageTraditionalSeleniumTests extends BaseSeleniumTests {
#Test
public void getSearchPage() {
this.driver.get("https://www.google.com");
WebElement element = this.driver.findElement(By.name("q"));
assertNotNull(element);
}
}
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
In my case in the following environment:
Windows 10
Python 3.7.5
Google Chrome version 80 and corresponding ChromeDriver in the path C:\Windows
selenium 3.141.0
I needed to add the arguments --no-sandbox and --remote-debugging-port=9222 to the ChromeOptions object and run the code as administrator user by lunching the Powershell/cmd as administrator.
Here is the related piece of code:
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--disable-infobars')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(options=options)
I ran into this problem on Ubuntu 20 with Python Selenium after first downloading the chromedriver separately and then using sudo apt install chromium-browser Even though they were the same version this kept happening.
My fix was to use the provided chrome driver that came with the repo package located at
/snap/bin/chromium.chromedriver
driver = webdriver.Chrome(chrome_options=options, executable_path='/snap/bin/chromium.chromedriver')
Update:
I am able to get through the issue and now I am able to access the chrome with desired url.
Results of trying the provided solutions:
I tried all the settings as provided above but I was unable to resolve the issue
Explanation regarding the issue:
As per my observation DevToolsActivePort file doesn't exist is caused when chrome is unable to find its reference in scoped_dirXXXXX folder.
Steps taken to solve the issue
I have killed all the chrome processes and chrome driver processes.
Added the below code to invoke the chrome
System.setProperty("webdriver.chrome.driver","pathto\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(options);
driver.get(url);
Using the above steps I was able to resolve the issue.
Thanks for your answers.
In my case it was problem with CI Agent account on ubuntu server, I solved this using custom --user-data-dir
chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')
My account used by CI Agent didn't have necessary permissions, what was interesting everything was working on root account
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')
driver = webdriver.Chrome(options=chrome_options)
url = 'https://www.google.com'
driver.get(url)
get_url = driver.current_url
print(get_url)
There is lot of possible reasons for the RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist error message (as we can see from the number of answers for this question). So let's dive deeper to explain what exactly this error message means.
According to chromedriver source code the message is created in ParseDevToolsActivePortFile method. This method is called from the loop after launching chrome process.
In the loop the driver check if the chrome process is still running and if the ParseDevToolsActivePortFile file was already created by chrome. There is a hardcoded 60s timeout for this loop.
I see two possible reasons for this message:
Chrome is really slow during startup - for example due to lack of system resources - mainly CPU or memory. In this case it can happen that sometimes chrome manage to start in time limit and sometimes not.
There is another issue which prevents chrome to start - missing or broken dependency, wrong configuration etc. In such case this error message is not really helpful and you should find another log message which explain the true reason of the failure.
It happens when chromedriver fails to figure out what debugging port chrome is using.
One possible cause is an open defect with HKEY_CURRENT_USER\Software\Policies\Google\Chrome\UserDataDir
But in my last case, it was some other unidentified cause.
Fortunately setting port number manually worked:
final String[] args = { "--remote-debugging-port=9222" };
options.addArguments(args);
WebDriver driver = new ChromeDriver(options);
As stated in this other answer:
This error message... implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Among the possible causes, I would like to mention the fact that, in case you are running an headless Chromium via Xvfb, you might need to export the DISPLAY variable: in my case, I had in place (as recommended) the --disable-dev-shm-usage and --no-sandbox options, everything was running fine, but in a new installation running the latest (at the time of writing) Ubuntu 18.04 this error started to occurr, and the only possible fix was to execute an export DISPLAY=":20" (having previously started Xvfb with Xvfb :20&).
You can get this error simply for passing bad arguments to Chrome. For example, if I pass "headless" as an arg to the C# ChromeDriver, it fires up great. If I make a mistake and use the wrong syntax, "--headless", I get the DevToolsActivePort file doesn't exist error.
I was stuck on this for a very long time and finally fixed it by adding this an additional option:
options.addArguments("--crash-dumps-dir=/tmp")
I know it's an old question and it already has a lot of answers. However, I ran into this issue, bumped into this thread and none of the proposed solutions helped. After spending a few days(!) on it I finally found a solution:
My problem was that I was using the selenium/standalone-chrome image on a MacBook with M1 chip. After switching to seleniarm/standalone-chromium everything finally started to work.
I had the same issue, but in my case chrome previously was installed in user temp folder, after that was reinstalled to Program files. So any of solution provided here was not help me. But if provide path to chrome.exe all works:
chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
I hope this helps someone =)
In my case it happened when I've tried to use my default user profile:
...
options.addArguments("user-data-dir=D:\\MyHomeDirectory\\Google\\Chrome\\User Data");
...
This triggered chrome to reuse processes already running in background, in such a way, that process started by chromedriver.exe was simply ended.
Resolution: kill all chrome.exe processes running in background.
update capabilities in conf.js as
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo-spec.js'],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
}
},
};
Old question but a similar issue nearly drove me to insanity so sharing my solution. None of the other suggestions fixed my issue.
When I updated my Docker image Chrome installation from an old version to Chrome 86, I got this error. My setup was not identical but we were instantiating Chrome through a selenium webdriver.
The solution was to pass the options as goog:chromeOptions hash instead of chromeOptions hash. I truly don't know if this was a Selenium, Chrome, Chromedriver, or some other update, but maybe some poor soul will find solace in this answer in the future.
For Ubuntu 20 it did help me to use my systems chromium driver instead of the downloaded one:
# chromium which
/snap/bin/chromium
driver = webdriver.Chrome('/snap/bin/chromium.chromedriver',
options=chrome_options)
And for the downloaded webdriver looks like it needs the remote debug port --remote-debugging-port=9222 to be set, as in one of the answers (by Soheil Pourbafrani):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome('<path_to>/chromedriver', options=chrome_options)
Date 9/16/2021
Everything works fine running chrome with selenium locally with python inside the docker hosted ubuntu container. When attempting to run from Jenkins the error above is returned WebDriverException: unknown error: DevToolsActivePort
Environment:
-Ubuntu21.04 inside a docker container with RDP access.
-chromedriver for chrome version: 93
Solution:
Inside the python file that starts the browser I had to set the DISPLAY environment variable using the following lines:
import os
os.environ['DISPLAY'] = ':10.0'
#DISPLAY_VAR = os.environ.get('DISPLAY')
#print("DISPLAY_VAR:", DISPLAY_VAR)
In my case, I was trying to create a runnable jar on Windows OS with chrome browser and want to run the same on headless mode in unix box with CentOs on it. And I was pointing my binary to a driver that I have downloaded and packaged with my suite. For me, this issue continue to occur irrespective of adding the below:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
options.setBinary("/pointing/downloaded/driver/path/in/automationsuite");
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("window-size=1024,768"); // Bypass OS security model
options.addArguments("--log-level=3"); // set log level
options.addArguments("--silent");//
options.setCapability("chrome.verbose", false); //disable logging
driver = new ChromeDriver(options);
Solution that I've tried and worked for me is, download the chrome and its tools on the host VM/Unix box, install and point the binary to this in the automation suite and bingo! It works :)
Download command:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
Install command:
sudo yum install -y ./google-chrome-stable_current_*.rpm
Update suite with below binary path of google-chrome:
options.setBinary("/opt/google/chrome/google-chrome");
And.. it works!
I also faced this issue while integrating with jenkins server, I was used the root user for jenkin job, the issue was fixed when I changed the user to other user. I am not sure why this error occurs for the root user.
Google Chrome Version 71.0
ChromeDriver Version 2.45
CentOS7 Version 1.153
I run selenium tests with Jenkins running on an Ubuntu 18 LTS linux. I had this error until I added the argument 'headless' like this (and some other arguments):
ChromeOptions options = new ChromeOptions();
options.addArguments("headless"); // headless -> no browser window. needed for jenkins
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
ChromeDriver driver = new ChromeDriver(options);
driver.get("www.google.com");
Had the same issue. I am running the selenium script on Google cloud VM.
options.addArguments("--headless");
The above line resolved my issue. I removed the other optional arguments. I think the rest lines of code mentioned in other answers did not have any effect on resolving the issue on the cloud VM.
in my case, when i changed the google-chrome and chromedriver version, the error was fixed :)
#google-chrome version
[root#localhost ~]# /usr/bin/google-chrome --version
Google Chrome 83.0.4103.106
#chromedriver version
[root#localhost ~]# /usr/local/bin/chromedriver -v
ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103#{#119})
ps: selenium verison was 3.9.1
No solution worked for my. But here is a workaround:
maxcounter=5
for counter in range(maxcounter):
try:
driver = webdriver.Chrome(chrome_options=options,
service_log_path=logfile,
service_args=["--verbose", "--log-path=%s" % logfile])
break
except WebDriverException as e:
print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
time.sleep(10)
if counter==maxcounter-1:
raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")
It seems there are many possible causes for this error. In our case, the error happened because we had the following two lines in code:
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
chromeOptions.setBinary(chromeDriverPath);
It's solved by removing the second line.
I ran into same issue, i am using UBUNTU, PYTHON and OPERA browser. in my case the problem was originated because i had an outdated version of operadriver.
Solution:
1. Make sure you install latest opera browser version ( do not use opera beta or opera developer), for that go to the official opera site and download from there the latest opera_stable version.
Install latest opera driver (if you already have an opera driver install, you have to remove it first use sudo rm ...)
wget https://github.com/operasoftware/operachromiumdriver/releases/download/v.80.0.3987.100/operadriver_linux64.zip
unzip operadriver_linux64.zip
sudo mv operadriver /usr/bin/operadriver
sudo chown root:root /usr/bin/operadriver
sudo chmod +x /usr/bin/operadriver
in my case latest was 80.0.3987 as you can see
Additionally i also installed chromedriver (but since i did it before testing, i do not know of this is needed) in order to install chromedriver, follow the steps on previous step :v
Enjoy and thank me!
Sample selenium code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Opera()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()
I came across the same problem, in my case there are two different common user userA and userB in Linux system.
userA first run the selinium programe which start chrome browswer with ChromeDriver successfully, when it came to userB, the DevToolsActivePort file doesn't exist error occur.
I tried the --remote-debugging-port=9222 option, but it lead to a new exception:
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
The I ran google-chome directory and see the following error:
mkdir /tmp/Crashpad/new: Permission denied (13)
The I search the problem and got this:
https://johncylee.github.io/2022/05/14/chrome-headless-%E6%A8%A1%E5%BC%8F%E4%B8%8B-devtoolsactiveport-file-doesn-t-exist-%E5%95%8F%E9%A1%8C/
chrome_options.add_argument(f"--crash-dumps-dir={os.path.expanduser('~/tmp/Crashpad')}")
Thanks to #johncylee.

org.openqa.selenium.SessionNotCreatedException: session not created disconnected:unable to send message to renderer error with ChromeDriver and Chrome

I try to run this simple program on Java with Selenium:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MySelenium {
public static void main(String[] args) {
System.out.println("First Selenium");
System.setProperty("webdriver.chrome.driver", "C:\\automation\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.seleniumhq.org/");
driver.quit();
}
}
But on running shows the following error:
How can i fixed this error ?
This error message...
org.openqa.selenium.SessionNotCreatedException: session not created
disconnected: unable to send message to renderer
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
I suspect your main issue is the incompatibility between the version of the binaries you are using.
As per the snapshot you have provided the following set of binaries you are using looks fine to me:
JDK: 1.8.0_191
Selenium: 3.14.0
ChromeDriver: 2.43
Chrome: 69.0
Analysis & Solution
As per Unable to receive message from renderer error using chrome driver 2.27 another pottential reason can be presence of antivirus within your localhost which you need to disable.
Ensure that /etc/hosts on your system contains the following entry:
127.0.0.1 localhost.localdomain localhost
#or
127.0.0.1 localhost loopback
Keep Chrome version between Chrome v68-70 levels. (as per ChromeDriver v2.43 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
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.
Reference
You can find a related discussion in Automation Testing Error : org.openqa.selenium.WebDriverException: disconnected: unable to connect to renderer
tl;dr
As per ChromeDriver 2.34 doesn't wait until iframe content loads after switching into iframe this issue was also observed with ChromeDriver 2.38 and Chrome 67+ combo and was related to static iframes (part of the originally loaded DOM) which seem to work correctly even till Chrome 66.
Try using JDK 1.8.0_181. I had the same issue after updating to JDK 1.8.0_191.

selenium server, selenium client, on an UBUNTU GUI server

i have a VPS with ubuntu 14.04 LTS and with the desktop package installed, that mean I can launch firefox from a ssh -X session.
To make tests, I launched from my server the selenium standalone server jar (selenium-server-standalone-3.0.0-beta3.jar)
After launching it, in another ssh session, i just enter python commands :
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
And after that, following the instructions from
http://selenium-python.readthedocs.io/getting-started.html#using-selenium-with-remote-webdriver, I enter :
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX)
After 45sec, i have lots of errors in both server window and client window.
Here is the main error :
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: GDK_BACKEND does not match available displays
I saw some people with the same problem, but even with the latest java and selenium versions, i still got this issue.
Thank you in advance for your help
It seems you're trying selenium 3 with latest firefox version. To support latest firefox with selenium 3, need to download latest geckodriver executable from this link and extract it into you system at any location.
Now to run selenium-server-standalone-3.0.0-beta3.jar use below command :-
java -jar selenium-server-standalone-3.0.0-beta3.jar -Dwebdriver.gecko.driver = "path/to/downloaded geckodriver"
Now you need to set capability with marionette property to true to support latest firefox with selenium 3 as below :-
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
# Tell the Python bindings to use Marionette.
caps["marionette"] = True
driver = webdriver.Remote(command_executor = 'http://127.0.0.1:4444/wd/hub', desired_capabilities = caps)
Note :- For more information about marionette follow this Mozilla official page

Selenium 2.53 not working on Firefox 47

I am getting error while using Firefox with WebDriver.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
Firefox version:47.0
Selenium:2.53.0
Windows 10 64 bit
Is anyone getting a similar issue or any idea what is the solution for this? It's working fine with Chrome but with Firefox none of the URLs are getting loaded.
Unfortunately Selenium WebDriver 2.53.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver) will be discontinued. As of version 3.0, Selenium WebDriver will need the geckodriver binary to manage Firefox browsers. More info here and here.
Therefore, in order to use Firefox 47.0 as browser with Selenium WebDriver 2.53.0, you need to download the Firefox driver (which is a binary file called geckodriver as of version 0.8.0, and formerly wires) and export its absolute path to the variable webdriver.gecko.driver as a system property in your Java code:
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
Luckily, the library WebDriverManager can do this work for you, i.e. download the proper Marionette binary for your machine (Linux, Mac, or Windows) and export the value of the proper system property. To use this library, you need to include this dependency into your project:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.0</version>
</dependency>
... and then execute this line in your program before using WebDriver:
WebDriverManager.firefoxdriver().setup();
A complete running example of a JUnit 4 test case using WebDriver could be as follows:
public class FirefoxTest {
protected WebDriver driver;
#BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
#Before
public void setupTest() {
driver = new FirefoxDriver();
}
#After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
#Test
public void test() {
// Your test code here
}
}
Take into account that Marionette will be the only option for future (for WebDriver 3+ and Firefox 48+), but currently (version 0.9.0 at writing time) is not very stable. Take a look to the Marionette roadmap for further details.
UPDATE
Selenium WebDriver 2.53.1 has been released on 30th June 2016. FirefoxDriver is working again with Firefox 47.0.1 as browser.
Try using firefox 46.0.1. It best matches with Selenium 2.53
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
I had the same issue and found out that you need to switch drivers because support was dropped. Instead of using the Firefox Driver, you need to use the Marionette Driver in order to run your tests. I am currently working through the setup myself and can post some suggested steps if you'd like when I have a working example.
Here are the steps I followed to get this working on my Java environment on Mac (worked for me in my Linux installations (Fedora, CentOS and Ubuntu) as well):
Download the nightly executable from the releases page
Unpack the archive
Create a directory for Marionette (i.e., mkdir -p /opt/marionette)
Move the unpacked executable file to the directory you made
Update your $PATH to include the executable (also, edit your .bash_profile if you want)
:bangbang: Make sure you chmod +x /opt/marionette/wires-x.x.x so that it is executable
In your launch, make sure you use the following code below (it is what I used on Mac)
Quick Note
Still not working as expected, but at least gets the browser launched now. Need to figure out why - right now it looks like I need to rewrite my tests to get it to work.
Java Snippet
WebDriver browser = new MarionetteDriver();
System.setProperty("webdriver.gecko.driver", "/opt/marionette/wires-0.7.1-OSX");
If you're on OSX using Homebrew, you can install old Firefox versions via brew cask:
brew tap goldcaddy77/firefox
brew cask install firefox-46 # or whatever version you want
After installing, you'll just need to rename your FF executable in the Applications directory to "Firefox".
More info can be found at the git repo homebrew-firefox. Props to smclernon for creating the original cask.
If you're on a Mac do brew install geckodriver and off you go!
In case anyone is wondering how to use Marionette in C#.
FirefoxProfile profile = new FirefoxProfile(); // Your custom profile
var service = FirefoxDriverService.CreateDefaultService("DirectoryContainingTheDriver", "geckodriver.exe");
// Set the binary path if you want to launch the release version of Firefox.
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe";
var option = new FirefoxProfileOptions(profile) { IsMarionette = true };
var driver = new FirefoxDriver(
service,
option,
TimeSpan.FromSeconds(30));
Overriding FirefoxOptions to provide the function to add additional capability and set Firefox profile because selenium v53 doesn't provide that function yet.
public class FirefoxProfileOptions : FirefoxOptions
{
private DesiredCapabilities _capabilities;
public FirefoxProfileOptions()
: base()
{
_capabilities = DesiredCapabilities.Firefox();
_capabilities.SetCapability("marionette", this.IsMarionette);
}
public FirefoxProfileOptions(FirefoxProfile profile)
: this()
{
_capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
}
public override void AddAdditionalCapability(string capabilityName, object capabilityValue)
{
_capabilities.SetCapability(capabilityName, capabilityValue);
}
public override ICapabilities ToCapabilities()
{
return _capabilities;
}
}
Note: Launching with profile doesn't work with FF 47, it works with FF 50 Nightly.
However, we tried to convert our test to use Marionette, and it's just not viable at the moment because the implementation of the driver is either not completed or buggy. I'd suggest people downgrade their Firefox at this moment.
New Selenium libraries are now out, according to: https://github.com/SeleniumHQ/selenium/issues/2110
The download page http://www.seleniumhq.org/download/ seems not to be updated just yet, but by adding 1 to the minor version in the link, I could download the C# version: http://selenium-release.storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip
It works for me with Firefox 47.0.1.
As a side note, I was able build just the webdriver.xpi Firefox extension from the master branch in GitHub, by running ./go //javascript/firefox-driver:webdriver:run – which gave an error message but did build the build/javascript/firefox-driver/webdriver.xpi file, which I could rename (to avoid a name clash) and successfully load with the FirefoxProfile.AddExtension method. That was a reasonable workaround without having to rebuild the entire Selenium library.
Its a FF47 issue
https://github.com/SeleniumHQ/selenium/issues/2110
Please downgrade to FF 46 or below (or try out FF48 developer https://developer.mozilla.org/en-US/Firefox/Releases/48)
Instructions on how to downgrade:
https://www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/
Or if you are on Mac, as suggested by someone else in this thread use brew.
Firefox 47.0 stopped working with Webdriver.
Easiest solution is to switch to Firefox 47.0.1 and Webdriver 2.53.1. This combination again works. In fact, restoring Webdriver compatibility was the main reason behind the 47.0.1 release, according to https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/.
You can try using this code,
private WebDriver driver;
System.setProperty("webdriver.firefox.marionette","Your path to driver/geckodriver.exe");
driver = new FirefoxDriver();
I upgraded to selenium 3.0.0 and Firefox version is 49.0.1
You can download geckodriver.exe from https://github.com/mozilla/geckodriver/releases
Make sure you download zip file only, geckodriver-v0.11.1-win64.zip file or win32 one as per your system and extract it in a folder.
Put the path for that folder in the "Your path to driver" quotes.Don't forget to put geckodriver.exe in the path.
I eventually installed an additional old version of Firefox (used for testing only) to resolve this, besides my regular (secure, up to date) latest Firefox installation.
This requires webdriver to know where it can find the Firefox binary, which can be set through the webdriver.firefox.bin property.
What worked for me (mac, maven, /tmp/ff46 as installation folder) is:
mvn -Dwebdriver.firefox.bin=/tmp/ff46/Firefox.app/Contents/MacOS/firefox-bin verify
To install an old version of Firefox in a dedicated folder, create the folder, open Finder in that folder, download the Firefox dmg, and drag it to that Finder.
Here's what the problem looked like in Wireshark
Just load up 2.53.1 and every thing will work.
As of September 2016
Firefox 48.0 and selenium==2.53.6 work fine without any errors
To upgrade firefox on Ubuntu 14.04 only
sudo apt-get update
sudo apt-get upgrade firefox
It seems to me that the best solution is to update to Selenium 3.0.0, download geckodriver.exe and use Firefox 47 or higher.
I changed Firefox initialization to:
string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe");
string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe");
File.Copy(geckoPathTest, geckoPath);
Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath);
_firefoxDriver = new FirefoxDriver();
I can confirm that selenium 2.53.6 works with firefox 44 for me on ubuntu 15.

action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build() works on windows but doesn't work on linux

action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build() works fine on windows but doesn't work on linux. I am writing a testcase using selenium webdriver and I am trying to select all the text which is written in a rich textbox and have used this code snippet to perform the select all command.It works fine on windows on firefox 38 browser but when I run my testcases on jenkins machine which is a linux machine,browser is firefox(don't know the exact version but above version 33) this code snippet doesn't work.I have tried some alternatives like driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "a")); and double click on rich textbox to select the text written in it but nothing works.What could be the reason,why these code snippets are not working on linux machine.
I have found the answer to my own question action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build() and driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "a"));was not running on Linux machine Firefox browser because the native events were not enabled in my driver factory.To enable Native Events you need to write the following code in the driver factory i.e where the required driver is created
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
FirefoxDriver driver = new FirefoxDriver(profile);

Categories