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.
Related
I am trying to launch Chrome with a specific Homepage set. Given below is the code, I am using:
package WebDriverInitialization;
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class LaunchChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\Technology Lab\\+ProgramFiles\\selenium-drivers\\chromedriver.exe");
Map<String, Object> hmPrefs = new HashMap<String, Object>();
hmPrefs.put( "browser.startup.page", 1);
hmPrefs.put( "browser.startup.homepage", "http://www.seleniumhq.org");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", hmPrefs);
DesiredCapabilities chromeCaps = DesiredCapabilities.chrome();
chromeCaps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver chromeDriver = new ChromeDriver(chromeCaps);
chromeDriver.manage().window().maximize();
}
}
When I run this, I get a blank page with 'data:,' in the URL - like how Chrome launches by default. Last line of the code is getting executed and the page is maximized.
I am using Selenium version 3.0.1; java version 1.8.0_92; Chrome version 56.0.2924.87 and ChromeDriver version 2.27.440174 on Windows 7 Professional SP1 x64.
Can anyone point out the mistake in above code and get it to launch Chrome with http://www.seleniumhq.org as the homepage?
Thanks!
Try this:
chromeOptions.setArguments("google-base-url=MY_URL");
From doc: Define kGoogleBaseURL
Specifies an alternate URL to use for speaking to Google. Useful for testing.
I am new in selenium and trying to open https://google.co.in in the chrome browser through selenium (below is the code). But I am not able to see the chrome browser after running this code. Could someone tell me that what's wrong with this code.
Here is my code.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:\\Application\\chrome.exe");
System.out.println("Loading...");
WebDriver driver = new ChromeDriver();
driver.get("http://google.co/in");
String appTitle = driver.getTitle();
System.out.println("Application title is :: "+appTitle);
driver.quit();
}
}
And the output is...
Loading...
Download chromedriver from this link : http://chromedriver.storage.googleapis.com/2.24/chromedriver_win32.zip , unzip it & put chromedriver.exe in "E:\Application" and provide path to chromedriver in System.setProperty("webdriver.chrome.driver", "E:\\Application\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", "E:\\Application\\chrome.exe");
Here E:\Application\chrome.exe is not your chrome driver.
Download the chrome driver of the version you need in your application.
Latest Release: ChromeDriver 2.24
Once you have the chrome driver , specify its location via the webdriver.chrome.driver system property (see sample below)
#Test
public void testGoogleSearch() {
// Optional, if not specified, WebDriver will search your path for chromedriver.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/xhtml");
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
driver.quit();
}
You can use a following library
webdrivermanager
after using this, you don't need to download a driver for the specific browser.It will automatically download driver for you and setup.
In order to use WebDriverManager in a Maven project, first add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>1.4.10</version>
</dependency>
Then you can let WebDriverManager to do manage WebDriver binaries for your application/test. Take a look to this JUnit example which uses Chrome with Selenium WebDriver:
public class ChromeTest {
protected WebDriver driver;
#BeforeClass
public static void setupClass() {
ChromeDriverManager.getInstance().setup();
}
#Before
public void setupTest() {
driver = new ChromeDriver();
}
#After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
#Test
public void test() {
// Using Selenium WebDriver to carry out automated web testing
}
}
Notice that simple adding ChromeDriverManager.getInstance().setup(); WebDriverManager does magic for you:
It checks the latest version of the WebDriver binary file
It downloads the binary WebDriver if it is not present in your system
It exports the required Java variable by Selenium WebDriver
So far, WebDriverManager supports Chrome, Opera, Internet Explorer, Microsoft Edge, PhantomJS, or Marionette as follows:
ChromeDriverManager.getInstance().setup();
InternetExplorerDriverManager.getInstance().setup();
OperaDriverManager.getInstance().setup();
EdgeDriverManager.getInstance().setup();
PhantomJsDriverManager.getInstance().setup();
MarionetteDriverManager.getInstance().setup();
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....");
}
}
I'm using windows on my system. I downloaded and extracted the chromedriver.exe file and I added it to my path.
Here is my code:
package com.chrometester.webdriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class chromeTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
}
}
But it comes back with an error:
Exception in thread "main" java.lang.IllegalStateException: The driver executable is a directory: C:\Users\Tgagn_000\Desktop\selenium\chrome
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome\\chromedriver.exe");
This should fix it. You should point to the driver file, not to its directory.
You are not adding the exe. Possibly
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
As error says, you have given directory path and not .exe path.
C:\Users\Tgagn_000\Desktop\selenium\chrome\ chromedriver.exe
Use below:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tgagn_000\\Desktop\\selenium\\chrome\\chromedriver.exe");
You have to be careful about order of the code:
You have to write setProperty code first then initialize the ChromeDriver()
below code sequence will give you an error
WebDriver driver= new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
driver.get("https://www.google.com/");
Below code will work
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.google.com/");
Issue
Trying to install a Firefox browser extension during remote execution of Selenium tests on Saucelabs. When executing the tests locally, the extension is installed and active in Firefox, but in remote execution on Saucelabs the extension does not appear in the list of installed extensions. Following the steps outlined in this Saucelabs support article.
Setup
Selenium.Support v2.48.2 or v2.49.0
Selenium.WebDriver v2.48.2 or v2.49.0
Windows 10 or 7
Firefox 43
C# test setup
private static FirefoxProfile CreateFirefoxProfile()
{
FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension("Tools/modify_headers-0.7.1.1-fx.xpi");
profile.SetPreference("general.useragent.override", "UA-STRING");
profile.SetPreference("extensions.modify_headers.currentVersion", "0.7.1.1-signed");
profile.SetPreference("modifyheaders.headers.count", 1);
profile.SetPreference("modifyheaders.headers.action0", "Add");
profile.SetPreference("modifyheaders.headers.name0", "SampleHeader");
profile.SetPreference("modifyheaders.headers.value0", "test1234");
profile.SetPreference("modifyheaders.headers.enabled0", true);
profile.SetPreference("modifyheaders.config.active", true);
profile.SetPreference("modifyheaders.config.alwaysOn", true);
profile.SetPreference("modifyheaders.config.start", true);
return profile;
}
private static IWebDriver GetRemoteDriver()
{
var capabilities = new DesiredCapabilities();
var profile = CreateFirefoxProfile();
capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile);
capabilities.SetCapability("name", buildContext);
capabilities.SetCapability(CapabilityType.BrowserName,"firefox");
capabilities.SetCapability(CapabilityType.Version,"");
capabilities.SetCapability(CapabilityType.Platform, "Windows 10");
capabilities.SetCapability("screen-resolution", "1280x1024");
capabilities.SetCapability("username", "SaucelabsUserName");
capabilities.SetCapability("accessKey", "SaucelabsAccessKey");
capabilities.SetCapability("build", "BuildNumber");
return new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com/wd/hub"), capabilities);
}
Firefox settings
When looking at about:support in Firefox during local execution and opening the user.js file, it includes the following extension setup which matches the web driver configuration. Inspecting user.js on the Saucelabs remote instance does not include that. Here's a paste bin of the contents of the remote user.js file.
user_pref("general.useragent.override", "UA-STRING");
user_pref("extensions.modify_headers.currentVersion", "0.7.1.1-signed");
user_pref("modifyheaders.headers.count", 1);
user_pref("modifyheaders.headers.action0", "Add");
user_pref("modifyheaders.headers.name0", "SampleHeader");
user_pref("modifyheaders.headers.value0", "test1234");
user_pref("modifyheaders.headers.enabled0", true);
user_pref("modifyheaders.config.active", true);
user_pref("modifyheaders.config.alwaysOn", true);
user_pref("modifyheaders.config.start", true);
I've also tried referencing an external version of the xpi with same result.
https://addons.mozilla.org/firefox/downloads/latest/967/addon-967-latest.xpi
Posted a bug report to SeleniumHQ and received this response, which fixed the above code.
In the RemoteWebDriver case for .NET, you need to use the
ToBase64String() method. This should resolve the issue. Note that this
is one of the reasons that other drivers have type-safe options
classes instead of passing raw capabilities. Future versions of the
.NET bindings should extend this pattern to Firefox as well, removing
this as an issue in the future.
The GetRemoteDriver method from above should be updated to this.
private static IWebDriver GetRemoteDriver()
{
var capabilities = new DesiredCapabilities();
var profile = CreateFirefoxProfile();
// Note the change here, calling .ToBase64String()
capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
capabilities.SetCapability("name", buildContext);
capabilities.SetCapability(CapabilityType.BrowserName,"firefox");
capabilities.SetCapability(CapabilityType.Version,"");
capabilities.SetCapability(CapabilityType.Platform, "Windows 10");
capabilities.SetCapability("screen-resolution", "1280x1024");
capabilities.SetCapability("username", "SaucelabsUserName");
capabilities.SetCapability("accessKey", "SaucelabsAccessKey");
capabilities.SetCapability("build", "BuildNumber");
return new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com/wd/hub"), capabilities);
}
After seeing what the fix is, I was able to find additional resources that mentioned this change.
https://stackoverflow.com/a/14285902/276681
https://code.google.com/p/selenium/issues/detail?id=2696#c4