I have chrome installed in my system. I'm using Selenium to run some tests on chrome.
I have downloaded the Chromedriver.exe to MyDocuments. I have set the 'webdriver.chrome.driver' using System.setProperty() and started ChromeDriver(). It works fine.
System.setProperty("webdriver.chrome.driver", "C:\\MyDocuments\\chromedriver.exe");
driver=new ChromeDriver();
Now, I'm trying to put Chromedriver.exe in a remote machine 'https://remotemachine/chromedriver.exe'. When I set the System property and start ChromeDriver(), I'm getting an exception, where Selenium is searching for chrome in a strange path:
The webdriver.chrome.driver defined chromedriver executable does not
exist in C:\Users..\Appdata\Local\Google
Chrome\Application...\https://remotemachine/chromedriver.exe
Why is Selenium searching for the chromedriver.exe by appending the system property to some location in C drive ?
How to launch Chrome from Selenium using a remote chromedriver.exe file ?
Not related to above, but:
Is it also possible to find the default browser binary path using Java/Selenium ?
It expects chrome to be in this location in windows
%HOMEPATH%\AppData\Local\Google\Chrome\Application\chrome.exe
For remote it has to be either in path or the -Dwebdriver.chrome.driver value should be pointing to a local chromedriver.exe location.
Local as in local to the place it is being run.
Here is the link for setup:
http://code.google.com/p/selenium/wiki/RemoteWebDriver
http://code.google.com/p/selenium/wiki/ChromeDriver
You cannot set the system path of a remote machine like -
System.setProperty("webdriver.chrome.driver", "remotemachine/chromedriver.exe");.
This code will get executed only in Hub/local machine where it resides.
To run it remotely, you need to mention -Dwebdriver.chrome.driver=pathtochromedriver.exe while starting the WD node.
java -jar seleniumserver.jar -role wd -hub http://hubhost:port/grid/register -Dwebdriver.chrome.driver=pathtochromedriver
System.setProperty("webdriver.chrome.driver", "C:\Documents and Settings\sssuppaluri\Desktop\Spicejet_Automation\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://149.122.160.94:8443/skylights/cgi-bin/skylights.cgi");
Create a new folder within your project called "chromedriver" and place the "chromedriver.exe" file in it then add the following line to your code
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\chromedriver\\chromedriver.exe");
Related
I have a maven project working fine with local Jenkins on Windows.
When I try to run the same test from Jenkins set up in LINUX, I am getting Firefox driver error.
selenium code:
System.setProperty("webdriver.gecko.driver", "/home/geckodriver");
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
options.setBinary("/usr/bin/firefox");
WebDriver driver = new FirefoxDriver(options);`
Error Message:
Specified firefox binary location does not exist or is not a real file: /usr/bin/firefox
Stacktrace:
Stacktrace
java.lang.IllegalStateException: Specified firefox binary location does not exist or is not a real file: /usr/bin/firefox
at com.google.common.base.Preconditions.checkState(Preconditions.java:504)
at org.openqa.selenium.firefox.Executable.(Executable.java:43)
at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:123)
at org.openqa.selenium.firefox.FirefoxOptions$Binary.asBinary(FirefoxOptions.java:420)
at java.util.Optional.map(Optional.java:215)
at org.openqa.selenium.firefox.FirefoxOptions.getBinaryOrNull(FirefoxOptions.java:220)
at org.openqa.selenium.firefox.FirefoxOptions.getBinary(FirefoxOptions.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:187)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:147)
at AutomationModules.LaunchBrowser.getDriver(LaunchBrowser.java:37)
at Validations.LoginValidation.StartBrowser(LoginValidation.java:26)
I tried not giving any binary files as well. It does not work
Expecting the test to run successfully from Jenkins
On my Ubuntu
/usr/bin/firefox -> ../lib/firefox/firefox.sh*
Which starts
/usr/lib/firefox/firefox
As I haven't changed Frirefox install location, this seems to be the default one, so probably this would work for you, too.
So try
options.setBinary("/usr/lib/firefox/firefox");
I am running basic selenium code with the help of selenium Grid.
Below are the steps:
Step 1 :- Downloaded the latest version of selenium Standalone server (3.4.0);
Step 2 :- Created HUB by using command java - jar <path of selenium standalone server>\\selenium-server-standalone-3.4.0.jar -role hub -> run successfully;
Step 3 :- Created node using command java -jar selenium-server-standalone-3.4.0.jar -role hub -node http://localhost:4444/grid/register -> run successfully;
Step 4 :- Created a simple selenium program with below code:
public class ClassName {
public static void main(String args[]) throws InterruptedException, MalformedURLException {
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
DesiredCapabilities cap=DesiredCapabilities.firefox();
cap.setPlatform(Platform.WINDOWS);
cap.setBrowserName("firefox");
URL url = new URL("http://localhost:4444/wd/hub");
WebDriver wd1 = new RemoteWebDriver(url, cap);
wd1.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
wd1.manage().window().maximize();
wd1.get("http://www.clickindia.com/");
wd1.findElement(By.linkText("Post Free Ad")).click();
Thread.sleep(3000);
wd1.findElement(By.linkText("Select category manually")).click();
Thread.sleep(3000);
WebElement country = wd1.findElement(By.id("combo_0"));
Select sel = new Select(country);
sel.selectByVisibleText("Jobs");
}
}
While running above code the following exception was thrown:
Note : If I run above code without remoteDriver and as a common WebDriver programm then it is working and running properly.
Location of selenium standalone server and Gecko file is same.
Gecko version is v0.16.0
Thanks in advance
The error message indicates that Selenium cannot find GeckoDriver binary in:
Any of the locations that are part of the PATH environment variable and
It could not find any valid value via the JVM argument (System.getProperty("webdriver.gecko.driver")) which represents geckodriver binary's location .
The line
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
ensures that only the current JVM (The JVM in which your ClassName.main() method is executing) knows of the location of the geckodriver binary. That is why your code runs fine when you work with FirefoxDriver.
But when you are working with RemoteWebDriver i.e., in the Grid mode, wherein you are trying to run against a Grid setup, setting the geckodriver location via the JVM argument "webdriver.gecko.driver" will not have any effect on the other JVMs (remember that the node which is responsible for supporting your browser interaction is spun off under a separate JVM using the command java -jar selenium-server-standalone-3.4.0.jar -role hub -node http://localhost:4444/grid/register (Your step 3).
To fix this, you have two options.
You use the JVM argument -Dwebdriver.gecko.driver when you are spawning the node and specify the location of the geckodriver.
You download geckodriver binary into a folder and include its location as part of your PATH variable (i.e., add C:\\geckodriver.exe to your PATH variable)
You have registered the node with default configuration as java -jar selenium-server-standalone-3.4.0.jar -role hub -node http://localhost:4444/grid/register. So your node is unable to process the request.
You can consider registering the node with the following configuration as:
java -Dwebdriver.gecko.driver=C:\\geckodriver.exe -jar selenium-server-standalone-3.4.0.jar -role node -hub http://localhost:4444/grid/register
Your code blocks works fine at my end.
How can I use Selenium to run for Google Chrome on Mac OS? I have put the code underneath but it is still giving me an error.
System.setProperty("webdriver.chrome.driver", "/Users/STQRY/Document/Jay");
WebDriver driver = new ChromeDriver();
ERROR:
".....The driver executable is a directory: /Users/STQRY/Document/Jay"
I've copied the path straight from the file when I right clicked and selected 'Copy File'.
Little google search can tell you that.
Download the chrome_driver (chromedriver_mac32.zip ) from this link if you haven't already : https://sites.google.com/a/chromium.org/chromedriver/
Unzip it.
Provide the path as follows.
System.setProperty("webdriver.chrome.driver", "/Path/To/ChromeDriver/chromedriver_mac");
Or
System.setProperty("webdriver.chrome.driver", "/Users/xyz/abc/chromedriver_mac_2.20");
Prior to doing the below step make sure that the downloaded zip file is unzipped first
Next provide the code as specified below,
System.setProperty("webdriver.chrome.driver", "/Users/STQRY/Document/Jay/chromedriver.exe");
WebDriver driver = new ChromeDriver();
Here is the error message I'm getting:
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Users\Scott\workspace\Twitch%20Bot%20v2\bin\chromedriver.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:122)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:117)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:118)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:291)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:82)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
at com.fatalcubez.main.Bot.setup(Bot.java:41)
at com.fatalcubez.main.Bot.<init>(Bot.java:29)
at com.fatalcubez.main.BotGUI.<init>(BotGUI.java:17)
at com.fatalcubez.main.Main.main(Main.java:14)
And here is the code that I'm using:
ClassLoader loader = ClassLoader.getSystemClassLoader();
URL path = loader.getResource("chromedriver.exe");
System.setProperty("webdriver.chrome.driver", path.getPath());
I've already check the directory for where it is searching for the chromedriver and it's there. I'm not sure what the problem is at this point. Any help would be great!
EDIT: It was simply a problem with spacing in the folder name, but now I have another problem. When I try to launch chrome it says "An administrator has installed chrome on this computer...." What can I do?
You have to give your chromeDriver.exe file path instead of taking the path from the URL.
example:
System.setProperty("webdriver.chrome.driver",
"C:\\Downloads\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver",
"/home/vin/Downloads/chromedriver");
Note- write the chromedriver without mentioning .exe (In Ubuntu and Mac)
Download the chromedriver:
chromedriver link
From here unzip the folder and copy choromedriver.exe in c now set path like
Locate your chrome driver file ( for windows) in the C drive under the user and the name of your device. Using any random folder and directing to that path will not work.
System.setProperty("webdriver.chrome.driver","C:\\Users\\hp\\chromedriver.exe");
This works for me, and I think the reason is, the driver will search for the path that identifies your pc, like a default folder where they search for, as it will be more time consuming to search for random folders and can create errors when you have multiple copies of that chromedriver.exe file like I had. Thanks, hope it works!
Another thing to add, when using chromedriver with windows, you must include .exe in your systems properties call.
valid call : System.setProperty("webdriver.chrome.driver", "res/chromedriver.exe");
invalid call : System.setProperty("webdriver.chrome.driver", "res/chromedriver");
System.setProperty("webdriver.chrome.driver",
"C:\Downloads\chromedriver.exe");
Navigate to this path, right click and open the chromedriver.exe then a pop up is open Uncheck "the Always ask before open" .
this works for me
In mac OS set the path as follows
System.setProperty("webdriver.chrome.driver",
"/Users/'user_name'/Downloads/chromedriver");
go to System preferences, in Security and privacy General tab you will see open chromedriver anyway, click on it and run your program again.
It works for me
You can add the address of chrome driver exe in your code:
System.setProperty("webdriver.chrome.driver",
"/path where exe is present/chromedriver.exe");
or you can directly copy paste the exe of chrome driver in you workspace (C:\Users\Scott\workspace\Twitch Bot v2\bin\)
This worked for me:
System.setProperty("webdriver.chrome.driver", "//Users//alinapanigrahi//bin//chromedriver");
WebDriver driver=new ChromeDriver();
But I got the unknown error:
unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"686.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=58.0.3029.110)
My Selenium Grid is showing an error:
org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property;
but I have specified it perfectly (according to my knowledge)
System.out.println("googlechrome");
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
System.setProperty("webdriver.chrome.driver", "D:\\testing\\zip file\\chromedriver_win_26.0.1383.0\\chromedriver.exe");
driver = new ChromeDriver();
I don't know what went wrong. This same code worked perfectly last week but now it doesn't.
if you are running the Grid, you need to set up Chromedriver executable in the node:
java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe
the most important part is the -D switcher which goes right after the chrome browser setup.
also, if you are running more than one nodes, that path must direct to the chromedriver executable on the concrete computer (node). Thats why I have it as relative path and not as a absolute path...
Is this not what you need?
File file = new File("D:\testing\zip file\chromedriver_win_26.0.1383.0\chromedriver.exe");
system.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver = new ChromeDriver(capability);