Selenium Webdriver 3- URL is not getting entered into the Firefox Browser - java

Windows 10 - 32 bit
Selenium Version:
3.0.0 beta 3
Browser:
Firefox 48.02
Eclipse Luna 32 bit
package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MyClass {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty "webdriver.firefox.marionette","D:\\Selenium\\geckodriver.exe");
//System.setProperty("webdriver.gecko.driver","D:\\Selenium\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Firefox and direct it to the Base URL
driver.get(baseUrl);
// get the actual value of the title
actualTitle = driver.getTitle();
/*
* compare the actual title of the page witht the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}
}
Error:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
les":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"1.5","maxVersion":"9.9"}],"targetPlatforms":[],"multiprocessCompatible":false,"signedState":0,"seen":true}

This kind of issues are coming in selenium 3.0 beta version.
If you are using using Selenium Standalone jar then you have to pass marionette as capabilities and initialize FirefoxDriver as follows:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
Tried with geckodriver v 0.10.0.
String driverPath = "<path to gecko driver executable>";
public WebDriver driver;
public void launchBrowser() {
System.out.println("launching firefox browser");
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
driver = new FirefoxDriver();
}

Related

URL is not opening in chrome in selenium

This is my code and requirement is that, need to open URL in same local chrome path. Is it possible??
public class Test{
public static void main(String args[]){
System.setProperty("webdriver.chrome.driver","C://Program Files (x86)//Google//Chrome//Application//chrome.exe");
WebDriver d= new ChromeDriver(); ;
String baseurl = "http://www.facebook.com/";
d.get(baseurl);
}
}
System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Downloads\\chromedriver83\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseurl = "http://www.facebook.com/";
driver.get(baseurl);
Check the path of chromedriver.exe carefully from your machine.
For Windows users:
System.setProperty("webdriver.chrome.driver","C:\\Users\\user\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");
For MAC users:
System.setProperty("webdriver.chrome.driver","//Users//apple//Downloads//chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");

How can I start the selenium Microsoft Edge?

I'm learning about Selenium webdriver test using Java to test my application.
I'm already implemented my tests to Google Chrome and Firefox, but the msedgedriver.exe is not opening the edge browser.
I'd like some help!
public WebDriver getDriver() {
return driver;
}
#BeforeAll
/*--- INICIALIZAÇÃO DO OGFIN*/
public void abrirOgfin() throws Exception {
String link;
int x=2;
switch(x) {
case 1:
System.setProperty("webdriver.gecko.driver", "C:\\workspace\\conf\\firefox\\geckodriver.exe");
driver = new FirefoxDriver();
//link = "http://sistema.ogfin.com.br/ogfin/Login"; //Servidor
link = "http://192.168.1.46:8888/ogfin/Login"; //Local
break;
case 2:
System.setProperty("webdriver.edge.driver", "C:\\workspace\\conf\\edge\\msedgedriver.exe");
driver = new EdgeDriver();
//link = "http://sistema.ogfin.com.br/ogfin/Login"; //Servidor
link = "http://192.168.1.46:8888/ogfin/Login"; //Local
break;
default:
System.setProperty("webdriver.chrome.driver", "C:\\workspace\\conf\\chromedriver.exe");
driver = new ChromeDriver();
link = "http://sistema.ogfin.com.br/ogfin/Login"; //Servidor
//link = "http://192.168.1.46:8888/ogfin/Login"; //Local
}
driver.manage().window().maximize();
driver.get(link);
}
When I run the code, the console show:
Starting MSEdgeDriver 75.0.139.20 (02d0ed4079b152f381df65e7da8a795530021fb1) on port 9579
Only local connections are allowed.
Please protect ports used by the WebDriver and related test frameworks to prevent access by malicious code.

How to set Proxy Authentication in seleniumWebdriver for Chrome Browser

I'm trying to Automate a web application selenium 2.0 [webdriver+java].The web application is currently deployed in our UAT servers on our local network.My test cases are executing, but I have to manually enter the Proxy Authentication details for my Chrome instance at the start of the test execution. I have tried all the solutions provided on stack overflow but still, the authentication message pops out.
This is the code I'm using in my driver initializing process
package com.misyn.ess.ui;
import java.util.Arrays;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
*
* #author User
*/
public class DriverClass {
private String baseUrl;
private String driverPath;
private String driverName;
private static WebDriver driver;
private static DriverClass driverClass;
private DriverClass() {
try {
baseUrl = "http://192.168.0.10:8282/ess";
driverPath = "E:\\Work_Folder\\SelTools\\chromedriver.exe";
driverName = "webdriver.chrome.driver";
//Set the location of the ChromeDriver
System.setProperty(driverName, driverPath);
//Create a new desired capability
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Create a new proxy object and set the proxy
Proxy proxy = new Proxy();
proxy.setHttpProxy("192.168.0.200:3128");
proxy.setSocksUsername("avishka");
proxy.setSocksPassword("12345678");
//Add the proxy to our capabilities
capabilities.setCapability("proxy", proxy);
//Start a new ChromeDriver using the capabilities object we created and added the proxy to
driver = new ChromeDriver(capabilities);
//Navigation to a url and a look at the traffic logged in fiddler
driver.navigate().to(baseUrl);
// System.setProperty(driverName, driverPath);
// driver = new ChromeDriver();
// driver.get(baseUrl);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Can anyone give me a solution how to give this proxy username and password thing from the application itself than manually entering details on the pop-up(Authentication), any help would be much appreciated.Thanks
the currently answered one is only for
As of Selenium 3.4 it is still in beta
Right now implementation is only done for InternetExplorerDriver
Where I'm using selenium 3.0 and Google Chrome as my web browser.
You can do via MultiPass for HTTP basic authentication
Download the extension from
https://chrome.google.com/webstore/detail/multipass-for-http-basic/enhldmjbphoeibbpdhmjkchohnidgnah
Download the extension as crx. You can get it as crx from chrome-extension-downloader
After that the config is simple.
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
/**
*
* #author Phystem
*/
public class ChromeAuthTest {
WebDriver driver;
public ChromeAuthTest() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
}
private void initDriver() {
ChromeOptions cOptions = new ChromeOptions();
cOptions.addExtensions(new File("MultiPass-for-HTTP-basic-authentication_v.crx"));
driver = new ChromeDriver(cOptions);
configureAuth(
"https://the-internet.herokuapp.com/basic_auth",
"admin",
"admin");
}
private void configureAuth(String url, String username, String password) {
driver.get("chrome-extension://enhldmjbphoeibbpdhmjkchohnidgnah/options.html");
driver.findElement(By.id("url")).sendKeys(url);
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.className("credential-form-submit")).click();
}
public void doTest() {
initDriver();
driver.get("https://the-internet.herokuapp.com/basic_auth");
System.out.println(driver.getTitle());
driver.quit();
}
public static void main(String[] args) {
new ChromeAuthTest().doTest();
}
}
I have used a sample site for testing.
Provide your url,username and password in the configure Auth function and try
public class DriverClass {
private String baseUrl;
private String driverPath;
private String driverName;
private static WebDriver driver;
private static DriverClass driverClass;
public DriverClass() {
try {
baseUrl = "http://192.168.0.10:8282/ess";
driverPath = "E:\\Work_Folder\\SelTools\\chromedriver.exe";
driverName = "webdriver.chrome.driver";
System.setProperty(driverName, driverPath);
Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setSslProxy("192.168.0.200" + ":" + 3128);
proxy.setFtpProxy("192.168.0.200" + ":" + 3128);
proxy.setSocksUsername("avishka");
proxy.setSocksPassword("12345678");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
driver = new ChromeDriver(desiredCapabilities);
driver.get(baseUrl);
} catch (Exception e) {
e.printStackTrace();
}
}
}
The proxy setting has been added with desired capabilities to pass values to proxy authentication,worked finally
This code (from Avishka Perera's answer) does not work for me:
proxy.setSocksUsername("avishka");
proxy.setSocksPassword("12345678");
The username and password set in this way do not take effect for the http/https proxy - the Proxy Authentication box still popped up.
I'm using Selenium java 3.141.0, ChromeDriver 2.33 and chrome 70. What works for me is to follow Mike's answer here Selenium using Python: enter/provide http proxy password for firefox .
Create the zip file, then add the extension like this:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addExtensions(new File("src/test/resources/proxy.zip"));
WebDriver driver = new ChromeDriver(chromeOptions);
One catch is that the above code will run into error if you set "--headless" argument because chrome in headless mode cannot have extension (Is it possible to run Google Chrome in headless mode with extensions?). If your Chrome runs in Docker container and cannot show the UI, then to get this solution work, you'll need to run with Xvfb instead of in headless mode.
Simple method to add authenticated proxy using selenium wire in Both firefox and chrome
In python
Step:1
pip3 install selenium-wire
Step:2
from seleniumwire import webdriver
from selenium import webdriver
step:3
Add proxy in below-mensioned format
proxy= "username:password#ip:port"
options = {'proxy': {'http': proxy, 'https': proxy, 'no_proxy': 'localhost,127.0.0.1,dev_server:8080'}}
step:4
pass proxy as an argument
CHROME
driver = webdriver.Chrome(options=chrome_options, executable_path="path of chrome driver", seleniumwire_options=options)
Firefox
driver = webdriver.Firefox(seleniumwire_options=options, executable_path="path of firefox driver", options=firefox_options)
step:5
Verify proxy applied by requesting the url https://whatismyipaddress.com/
time.sleep(20)
driver.get("https://whatismyipaddress.com/")
Note:
But selenium log shows it runs in without proxy because we are using an external package to apply proxy.
I know this is an old thread, still leaving a solution which worked for me using browsermob proxy, for someone who still needs an option.
Maven dependency:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-core</artifactId>
<version>2.1.5</version>
</dependency>
Java Code:
// I am using firefox
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
BrowserMobProxy browsermobProxy = new BrowserMobProxyServer();
browsermobProxy.setChainedProxy(new InetSocketAddress(PROXY_HOSTNAME, PROXY_PORT));
browsermobProxy.chainedProxyAuthorization(PROXY_USERNAME, PROXY_PASSWORD, AuthType.BASIC);
browsermobProxy.start(0);
FirefoxBinary firefoxBinary = new FirefoxBinary();
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary );
firefoxOptions.setProfile(firefoxProfile);
firefoxOptions.setProxy(ClientUtil.createSeleniumProxy(browsermobProxy));
WebDriver webDriverWithProxy = new FirefoxDriver(firefoxOptionsWithProxy);
webDriverWithProxy.get("https://stackoverflow.com/");
The approach that worked perfectly fine for me is by using AutoIT.
Install autoIT and prepare a simple script as shown in the picture attached and execute the script file from your testscript using Runtime.getRuntime().exec("\YOUR_SCRIPT.exe") before navigating to the baseURL.

Firefox browser is not opening in Selenium webdriver in eclipse

I'm using Firefox 45.8.0 version and I tried below code to open Firefox browser but i'm getting error that: "The path to the driver executable must be set by the webdriver.gecko.driver system property".
Please sagest me how to set the path.
Note:gecko driver will work for above firefox version 48.
package First;
import org.openqa.selenium.firefox.FirefoxDriver;
public class City {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver c1=new FirefoxDriver();
c1.get("http://google.com");
}
}
Try this below code.
In your code you were not provide gecko driver path. You can download gecko driver from this link
public class City {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("http://google.com");
}
}

selenium webdriver Grid

hi i am using selenium webdriver. i have to connect system and i phone for the testing
when i connect its not opening the other system, i am using chrome 38 and ie 10
i am getting stuct, please provide me your answer. check the code
if(browser.equalsIgnoreCase("Internet Explorer")){
caps = DesiredCapabilities.internetExplorer();
}
if(browser.equalsIgnoreCase("chrome")){
//System.setProperty("webdriver.chrome.driver","/10.187.143.46/C:/chr/chromedriver.exe");
//driver=new RemoteWebDriver(new URL("http://10.187.143.46:6767/wd/hub"),caps);
//ChromeDriver driver = new ChromeDriver();
// driver.get("http:\\www.google.com");
System.setProperty("webdriver.chrome.driver","\\10.187.143.46\\c$\\Users\\rr188182\\Desktop\\chromedriver.exe");
caps=DesiredCapabilities.chrome();
}
//Version
caps.setVersion(i);
driver1=new RemoteWebDriver(new URL("http://10.187.143.89:6767/wd/hub"),caps);
driver1.get("http://www.google.com");
driver2=new RemoteWebDriver(new URL("http://10.187.143.165:6767/wd/hub"),caps);
driver2.get("http://www.google.com");
driver3=new RemoteWebDriver(new URL("http://10.187.143.25:6767/wd/hub"),caps);
driver3.get("http://www.google.com");
driver4=new RemoteWebDriver(new URL("http://10.187.143.46:5555/wd/hub"),caps);
driver4.get("http://www.google.com");
driver5=new RemoteWebDriver(new URL("http://10.187.143.163:6767/wd/hub"),caps);
driver5.get("http://www.google.com");
public static void main(String[] args) throws MalformedURLException {
GridConcept gr=new GridConcept();
//gr.setup("WINDOWS", "internet explorer", "11","http://www.google.com");
...
}
if i provide ie and firefox the browser is opening but the next line is not excuting, if i use chrome it shows error as valid path. please provide your comments. Thanks in advance

Categories

Resources