Firefox 48 and Selenium timeout issue - java

I am unable to run my tests on Firefox 48 using latest Selenium versions (2.53, Selenium 3 beta).
Please explain the configuration needed and the code to use to successfully run tests on Firefox 48. I have pointed to the geckodriver and tried to initialise the same in my code.
Code:
System.setProperty("webdriver.gecko.driver","E:\\Work\\Selenium\\geckodriver-v0.9.0-win64\\geckodriver.exe");
WebDriver driver = null;
driver = new MarionetteDriver();
Getting the below:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:

Worked for me:
System.setProperty("webdriver.gecko.driver", "PATH TO GECKO DRIVER");
DesiredCapabilities ffCapabilities = DesiredCapabilities.firefox();
ffCapabilities.setCapability("marionette",true);
WebDriver driver = new FirefoxDriver(ffCapabilities);

You need to write DesiredCapabilities. Add this line before driver initialization.
DesiredCapabilities cap = DesiredCapabilities.firefox()

You can download geckodriver from the link
https://github.com/mozilla/geckodriver/releases
Then save the file in your local system. unzip the file and change the application name as "wires.exe".
Then specify the path upto wires.exe in the code.
add selenium-2.53.0 jar files.
Try below code to start working on FF 47.0 or above.
package com.marionette.programs;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.MarionetteDriver;
public class HandleLatestFirefox {
public static void main(String[] args) {
String currentDir = System.getProperty("user.dir");
System.out.println(currentDir);
//String marionetteDriverLocation = currentDir + "G:\\ravik\\Ravi-Training\\Selenium\\Marionette for firefox\\wires.exe";
System.setProperty("webdriver.gecko.driver", "G:\\ravik\\Ravi-Training\\Selenium\\Marionette for firefox\\wires.exe");
WebDriver driver = new MarionetteDriver();
driver.get("https://www.google.co.in/webhp?hl=en&sa=X&ved=0ahUKEwjdgc21jJHOAhVCvY8KHZ4aCdcQPAgD");
System.out.println("marionette working fine....");
}
}

Related

Insecure Connection error Firefox v 53.0

I am using selenium 3.4.0 , firefox version 53.0 and gecko driver 0.16.1 , java compiler 1.7.
For some sites insecure connection error is displayed.
I have used firefox profile object as follow but still it's not resolving:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", 3128);
WebDriver driver = new FirefoxDriver(profile);
driver.manage().window().maximize();
To work with Selenium 3.4.0 with Mozilla Firefox browser 53.x you need to download the latest geckodriver from here. Save it in your machine & provide the absolute path of the geckodriver.
Create a new Firefox profile manually by the name debanjan and use the AcceptUntrustedCertificates & setAssumeUntrustedCertificateIssuer options.
This code executes fine with some simple tweak to your own code.
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
testprofile.setAcceptUntrustedCertificates(true);
testprofile.setAssumeUntrustedCertificateIssuer(true);
testprofile.setPreference("network.proxy.type", 1);
testprofile.setPreference("network.proxy.http", "localhost");
testprofile.setPreference("network.proxy.http_port", 3128);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, testprofile);
dc.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(dc);
Let me know if this helps you.
Try using firefox below 48 version. You won't face any problem or include below code in your existing code:
System.setProperty("webdriver.firefox.bin" ,"C:/Users/siddhesh.kalgaonkar/AppData/Local/Mozilla Firefox/firefox.exe");
It should solve your problem because this is what I use for current firefox version.
Use Firefox 54.0 64bit, Selenium v3.4.0, jcommender v1.7, TestNG v6.9.9, Java v8.0, Gecko driver v0.17.0
Use below code-
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
public class AppUrl {
public static WebDriver driver;
public static final String url = "https://10.10.1.1";
#BeforeTest
public void setup() throws Exception {
System.setProperty("webdriver.gecko.driver","C:/Users/Downloads/geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setAcceptInsecureCerts(true);
driver = new FirefoxDriver(desiredCapabilities);
driver.get(url);
}
}
Even I tried other sample codes from different sites. Today after I upgrade all the softwares and run the code, it worked for me.

Selenium WebDriver can find element in Chrome but not in FireFox

I'm still new to working with FireFox and using the Selenium Driver. I wrote the following driver code in Java as part of a CucumberTest. I have the ChromeDriver section commented out. When I comment out the FirefoxDriver and run this using the ChromeDriver line it works as expected. However, when I try to run the exact same code swapped to the FirefoxDriver, I get to my first when statement and I get a nullPointerException at the first find element by id line. Is there a workaround?
#When("^User enters \"(.*)\" and \"(.*)\"$")
public void user_enters_UserName_and_Password(String realUsername, String realPassword)
throws Throwable {
System.out.println(realUsername + " " + realPassword);
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(realUsername);
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(realPassword);
driver.findElement(By.id("loginbutton")).click();
}
EDIT: The issue was in how I was calling the driver. I corrected how I initilzed my driver to this and it worked. Something about how I was calling it before caused it to get discarded so it was null by the time it came to this step.
The issue was in how I was instantiating the Firefox driver in a different file. This is what worked ' String marionetteDriverLocation = "c://Features//geckodriver.exe";
System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
//create firefox profile
FirefoxProfile myProfile= new FirefoxProfile();
// This will set the true value
myProfile.setAcceptUntrustedCertificates(true);
//setup the driver with profile settings for security issues.
driver = new FirefoxDriver(myProfile);'

How to run ghostdriver with Selenium using java

I want to use phantomJS for some web testing, and I've come across GhostDriver (https://github.com/detro/ghostdriver). I've built it using the instructions in the readme and I can run it on a specified port, but I am not sure how to access the web driver from my java code. To clarify, I've seen this example in ruby:
caps = {
:browserName => "phantomjs",
:platform => "LINUX"
}
urlhub = "http://key:secret#hub.testingbot.com:4444/wd/hub"
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
#webdriver = Selenium::WebDriver.for :remote, :url => urlhub, :desired_capabilities => caps, :http_client => client
#webdriver.navigate.to "http://www.google.com/"
puts #webdriver.title
#webdriver.save_screenshot("./screenshot.png")
#webdriver.quit
I'm just not sure how to do the same from java.
Just to clarify for others who might see this, to run it from java:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"/Path/to/bin/phantomjs");
driver = new PhantomJSDriver(caps);
Then it can be used like a usual WebDriver.
I believe this link will answer your questions. You will need Selenium 2.28.0, and PhantomJS 1.8. I have tested this, and it works as advertised, although my tests were precursory. Note that you need to download the Selenium zip file to get the jar which contains the bindings. The Maven repo does not yet include it.
http://ivandemarino.me/2012/12/04/Finally-GhostDriver-1-0-0/
First download the exe file of the PhantomJSDriver. Don't need to install, only download this file from http://phantomjs.org/download.html and simply give the path of the exe file in the given code.
public class Browserlaunch {
public static void main(String[] args) {
DesiredCapabilities DesireCaps = new DesiredCapabilities();
DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/Drivers/phantomjs/bin/phantomjs.exe");
WebDriver driver=new PhantomJSDriver(DesireCaps);
driver.get("http://google.com");
}
}
Only set system property:
System.setProperty("phantomjs.binary.path", "lib/phantomjs.exe");
WebDriver driver = new PhantomJSDriver();

Passing options to chrome driver selenium

I am trying to disable the output to the console for chrome. If I pass the --start-maximized option it works fine. I may have the wrong command?
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--silent"));
chrome = new ChromeDriver(_chromeservice,capabilities);
I also tried
ChromeOptions options = new ChromeOptions();
options.addArguments("silent");
chrome = new ChromeDriver(options);
Output
Started ChromeDriver port=26703 version=23.0.1240.0
log=/Brett/workspace/TestNG/chromedriver.log
[1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends
[1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends
[1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending
sendsBlockquote
Hinted by this Chromedriver ticket (about the silent option), I looked in the source of ChromeDriverService.java, and found a reference to "webdriver.chrome.logfile".
After adding -Dwebdriver.chrome.logfile="/dev/null" to my java command, the logs became readable again: The usless ChromeDriver logs were gone, while theSystem.out.println calls and exceptions are still shown in the console.
I start java with the following parameters (Linux / Mac):
DIR=path/to/dir/containing/selenium/and/stuff
cd "$DIR" && java -cp "$DIR\
:$DIR/output\
:$DIR/bin/selenium-server-standalone-2.33.0.jar" \
-Dwebdriver.chrome.driver="$DIR/bin/chromedriver" \
-Dwebdriver.chrome.args="--disable-logging" \
-Dwebdriver.chrome.logfile="/dev/null" \
AllTests
If you're on Windows:
set DIR=path\to\dir\containing\selenium\and\stuff
cd "%DIR%" && java -cp "%DIR%;%DIR%\output;%DIR%\bin\selenium-server-standalone-2.33.0.jar" ^
-Dwebdriver.chrome.driver="%DIR%\bin\chromedriver.exe" ^
-Dwebdriver.chrome.args="--disable-logging" ^
-Dwebdriver.chrome.logfile=NUL ^
AllTests
Explanation for the composition of my classpath (-cp): My tests are located in a directory at "$DIR/output". The Selenium jar file is placed in "$DIR/bin/selenium-server-standalone-2.33.0.jar". "AllTests" is the name of my class containing public static void main(String[] args) - this launches my tests.
The other parameters are self-explanatory, adjust it to your needs. For convenience (used in a shell/batch script), I've declared the common directory in a variable DIR.
When I was setting chrome up with
selenium-chrome-driver-2.48.2.jar
chromedriver 2.20
selenium-java-2.48.2.jar
none of the above answers worked for me,
Since I see some of the answers are a few years old, I will post what worked for me.
ChromeOptions chromeOptions = setupChromeOptions();
System.setProperty("webdriver.chrome.logfile", "\\path\\chromedriver.log");
System.setProperty("webdriver.chrome.driver", "\\path\\chromedriver.exe");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
driver = new ChromeDriver(chromeOptions);
Try "--disable-logging" instead.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--disable-logging"));
chrome = new ChromeDriver(_chromeservice,capabilities);
As of Selenium 3 at least, you can use ChromeDriverService and its inner class Builder to be able to launch the driver in silent mode.
A oneliner for that:
new ChromeDriver(new ChromeDriverService.Builder().withSilent(true).build());
The constructor is straight-forward, you create a new service builder setting silent to true (that's the critical part) and you finally build it into a ChromeDriverService which is required by ChromeDriver's constructor.

Driver executable must be set by the webdriver.ie.driver system property

I am using Selenium for automating the tests. My application exclusively uses IE, it will not work on other Browsers.
Code:
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class Test {
public static void main(String[] args) {
final String sUrl = "http://www.google.co.in/";
System.setProperty("webdriver.chrome.driver","C:\\Users\\vthaduri\\workspace\\LDCSuite\\IEDriverServer.exe");
WebDriver oWebDriver = new InternetExplorerDriver();
oWebDriver.get(sUrl);
WebElement oSearchInputElem = oWebDriver.findElement(By.name("q")); // Use name locator to identify the search input field.
oSearchInputElem.sendKeys("Selenium 2");
WebElement oGoogleSearchBtn = oWebDriver.findElement(By.xpath("//input[#name='btnG']"));
oGoogleSearchBtn.click();
try {
Thread.sleep(5000);
} catch(InterruptedException ex) {
System.out.println(ex.getMessage());
}
oWebDriver.close();
}
}
And here is the error I am getting
The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://www.seleniumhq.org/download/
Jun 12, 2012 4:18:42 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed
Jun 12, 2012 4:18:42 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
Can someone help me on this?
You will need InternetExplorer driver executable on your system. So download it from the hinted source (http://www.seleniumhq.org/download/) unpack it and place somewhere you can find it. In my example, I will assume you will place it to C:\Selenium\iexploredriver.exe
Then you have to set it up in the system. Here is the Java code pasted from my Selenium project:
File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
Basically, you have to set this property before you initialize driver
The error message says
"The path to the driver executable must be set by the
webdriver.ie.driver system property;"
You are setting the path for the Chrome Driver with "webdriver.chrome.driver" property. You are not setting the file location when for InternetExplorerDriver, to do that you must set "webdriver.ie.driver" property.
You can set these properties in your shell, via maven, or your IDE with the -DpropertyName=Value
-Dwebdriver.ie.driver="C:/.../IEDriverServer.exe"
You need to use quotes because of spaces or slashes in your path on windows machines, or alternatively reverse the slashes other wise they are the string string escape prefix.
You could also use
System.setProperty("webdriver.ie.driver","C:/.../IEDriverServer.exe");
inside your code.
I just put the driver files directly into my project to not get any dependency to my local machine.
final File file = new File("driver/chromedriver_2_22_mac");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver = new ChromeDriver();
For spring :
File inputFile = new ClassPathResource("\\chrome\\chromedriver.exe").getFile();
System.setProperty("webdriver.chrome.driver",inputFile.getCanonicalPath());
You will need have to download InternetExplorer driver executable on your system, download it from the source (http://code.google.com/p/selenium/downloads/list) after download unzip it and put on the place of somewhere in your computer. In my example, I will place it to D:\iexploredriver.exe
Then you have write below code in your eclipse main class
System.setProperty("webdriver.ie.driver", "D:/iexploredriver.exe");
WebDriver driver = new InternetExplorerDriver();

Categories