How to set Google Chrome in WebDriver - java

I am trying to set Chrome as my browser for testing with Web-Driver and set the chromedriver.exe file properly but I am still getting the following error:
org.openqa.selenium.WebDriverException:
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.
The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
I have already checked the path of the driver but still i am getting same error.
I don't know where i have made a mistake.
Here is my code:
File file = new File("C:\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Capability= DesiredCapabilities.chrome();
Capability.setBrowserName("chrome");
Capability.setPlatform(Platform.LINUX);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);
browser.get(webUrl);
Please help me!!

Aditya,
As you said in your last comment that you are trying to access chrome of some other system so based on that you should keep your chrome driver in that system itself.
for example: if you are trying to access linux chrome from windows then you need to put your chrome driver in linux at some place and give permission as 777 and use below code at your windows system.
System.setProperty("webdriver.chrome.driver", "\\var\\www\\Jar\\chromedriver");
Capability= DesiredCapabilities.chrome(); Capability.setPlatform(org.openqa.selenium.Platform.ANY);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);
This is working code of my system.

I'm using this since the begin and it always work. =)
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");

For Mac -Chrome browser
public class MultipleBrowser {
public WebDriver driver= null;
String browser="mozilla";
String url="https://www.omnicard.com";
#BeforeMethod
public void LaunchBrowser() {
if(browser.equalsIgnoreCase("mozilla"))
driver= new FirefoxDriver();
else if(browser.equalsIgnoreCase("safari"))
driver= new SafariDriver();
else if(browser.equalsIgnoreCase("chrome"))
System.setProperty("webdriver.chrome.driver","/Users/mhossain/Desktop/chromedriver");
driver= new ChromeDriver();
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
driver.navigate().to(url);
//driver.manage().deleteAllCookies();
}

It was giving Illegal Exception.
My workaround with code:
public void dofirst(){
System.setProperty("webdriver.chrome.driver","D:\\Softwares\\selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");
}

Mac OS:
You have to install ChromeDriver first:
brew cask install chromedriver
It will be copied to /usr/local/bin/chromedriver. Then you can use it in java code classes.

public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver","Absolute path of Chrome driver");
driver =new ChromeDriver();
baseUrl = "URL/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

Related

Selenium opening browser but not loading websites in Java

I am using Selenium in a Burp plugin but I can't load pages with the get method. Browsers open correctly, both Firefox and Chrome, but they don't load the page. Chrome address bar shows "data;.", while Firefox has no text in it. I am using the last driver available, Chrome 81.0.4044.183 and the driver for this exact version, while Firefox is 76.0.1 and I am using GeckoDriver 0.24 (since 0.25+ have a known bug) and it works with the last version of Firefox.
The code is the following
void runBrowserAutomatization(File fileDriver, String seleniumTrack, boolean isHeadless) {
WebDriver driver;
if (gui.usedBrowser().toLowerCase().contains("chrome")) {
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8080");
proxy.setSslProxy("localhost:8080");
options.setCapability(CapabilityType.PROXY, proxy);
options.setHeadless(isHeadless);
System.setProperty("webdriver.chrome.driver", fileDriver.getPath());
driver = new ChromeDriver(options);
} else if (gui.usedBrowser().toLowerCase().contains("firefox")) {
FirefoxOptions options = new FirefoxOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8080");
proxy.setSslProxy("localhost:8080");
options.setCapability(CapabilityType.PROXY, proxy);
options.setHeadless(isHeadless);
System.setProperty("webdriver.gecko.driver", fileDriver.getPath());
driver = new FirefoxDriver(options);
} else {
PrintMsg("No browser selected...");
return;
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.nytimes.com/");
driver.quit();
}
I may also think it is a Proxy misconfiguration, Burp certificate is installed in Firefox and Windows (where Chrome gets Certificate Authorities) but is not shown in the settings of the instance started by Selenium. Any help or suggestion is highly appreciated, thnaks.

Login failed message does not appear on a website while using selenium

I am trying to log in into a website using selenium.The end site provides a access denied message if i enter wrong credentials and submit the login form(without selenium).But when i do the same stuff using selenium,the access denied message does not appear. Any suggestions?
URL : https://oa.lombardfinance.com.au/
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
WebDriver driver = new ChromeDriver(options);
JavascriptExecutor js = (JavascriptExecutor)driver;
driver.get("https://oa.lombardfinance.com.au/");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtClientNumber")).sendKeys("Subrat");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtPassword")).sendKeys("Subrat");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtCaptcha")).sendKeys("Subrat");
//WebElement loginForm = driver.findElement(By.id("aspnetForm"));
//js.executeScript("arguments[0].submit();", loginForm);
WebElement login = driver.findElement(By.id("ctl00_ContentPlaceHolder1_btnLogin2"));
new Actions(driver).moveToElement(login).click().perform();
Just tried the same code you're using with a slight difference in driver initiation:
System.setProperty("webdriver.chrome.driver", "\path\to\chromedriver.exe");
WebDriver driver = new ChromeDriver();
I excluded the line:
options.addArguments("disable-infobars");
and the Selenium test shows Access denied as well.
Try using the below code:
System.setProperty("webdriver.chrome.driver", "\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
The solution is more convenient one because some times browser shows developer mode issue.

WebDriver vs ChromeDriver

In Selenium 2 - Java, what's the difference between
ChromeDriver driver = new ChromeDriver();
and
WebDriver driver = new ChromeDriver();
? I've seen both of these used in various tutorials, examples, etc and am not sure about the difference between utilizing the ChromeDriver vs WebDriver objects.
Satish's answer is correct but in more layman's terms, ChromeDriver is specifically and only a driver for Chrome. WebDriver is a more generic driver that can be used for many different browsers... IE, Chrome, FF, etc.
If you only cared about Chrome, you might create a driver using
ChromeDriver driver = new ChromeDriver();
If you want to create a function that returns a driver for a specified browser, you could do something like the below.
public static WebDriver startDriver(Browsers browserType)
{
switch (browserType)
{
case FIREFOX:
...
return new FirefoxDriver();
case CHROME:
...
return new ChromeDriver();
case IE32:
...
return new InternetExplorerDriver();
case IE64:
...
return new InternetExplorerDriver();
default:
throw new InvalidParameterException("Unknown browser type");
}
}
public enum Browsers
{
CHROME, FIREFOX, IE32, IE64;
}
... and then call it like...
WebDriver driver = startDriver(Browsers.FIREFOX);
driver.get("http://www.google.com");
and depending on what browser you specify, that browser will be launched and navigate to google.com.
WebDriver is an interface, while ChromeDriver is a class which implements WebDriver interface. Actually ChromeDriver extends RemoteWebDriver which implements WebDriver. Just to add Every WebDriver like ChromeDriver, FirefoxDriver, EdgeDriver are supposed to implement WebDriver.
Below are the signatures of ChromeDriver and RemoteDriver classes
public class ChromeDriver extends RemoteWebDriver
implements LocationContext, WebStorage {}
public class RemoteWebDriver implements WebDriver, JavascriptExecutor,
FindsById, FindsByClassName, FindsByLinkText, FindsByName,
FindsByCssSelector, FindsByTagName, FindsByXPath,
HasInputDevices, HasCapabilities, TakesScreenshot {}
WebDriver is an interface
ChromeDriver is an implementation of the WebDriver interface
https://docs.oracle.com/javase/tutorial/java/concepts/interface.html
There is no difference in usage:
ChromeDriver driver = new ChromeDriver();
or
WebDriver driver = new ChromeDriver();
This can be the simplest point:
ChromeDriver is only specific to Chrome Browser
WebDriver is global for all Browsers

Selenium WebDriver on IE11 always has "--port=" in URL

I am trying to run some automated tests on IE11 using Selenium Webdriver. Whenever I run my code the URL that IE tries to load is http://--port=38198/
I am trying to simply load Google and return the title, then I will move onto the actual automated testing I intend to do.
Here is a sample of my code so far;
private WebDriver driver;
private String baseUrl;
#Before
public void setUp() throws Exception{
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
baseUrl = "http//www.google.com";
driver = new InternetExplorerDriver(cap);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception{
driver.get(baseUrl);
System.out.println(driver.getTitle());
//driver.navigate().to(baseUrl);
}
Ever time I run my code it always opens the same URL - http://--port=
From my code I can't see where I have gone wrong. I changed the security settings on IE to medium and disabled protected mode (I have tried it with protected mode turned on and still no luck). I have also downloaded and installed Microsofts IE11 web driver.
I am totally mystified by this, can someone give me any insight into this...
It seems that you are using your native Windows IE?
You have to download the IE WebDriver from https://code.google.com/p/selenium/wiki/InternetExplorerDriver and your webdriver.ie.driver property needs the path to the downloaded IEDriverServer.exe
Please try and report if that solves your problem. If not I will change my chrome WebDriver to the IE and try it myself :)

How can I run Selenium Webdriver test case using ChromeDriver?

I have done this
File file = new File("path\\to\\chrome driver");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
Totally I have 5 testcases to test. But when testing only 2 or 3 test cases are running and the remaining are not.
Then I got error as,
[1207/104351:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends
[1207/104351:ERROR:automation_proxy.cc(319)] Channel error in AutomationProxy.
My test cases are in java and i'm trying this is Windiws OS
What is this how can I fix this?
This is an issue with Chromedriver.Refer this link Chromedriver Issue
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
Download chromedriver.exe from internet.
Set the path to the chrome.exe.

Categories

Resources