How to put file path of chromedrive on Eclipse - java

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();

Related

download.default_directory selenium java not working in 84 chrome driver

I am not able to change the default chrome driver download path in selenium java.
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("download.default_directory", " path ");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
ChromeDriver driver= new ChromeDriver(options);
Your code is great and meets the official manual.
I think the problem is with path parameter.
The following come from the chromedriver official manual:
However, there are several caveats to be aware of:
Chrome disallows using certain directories for download. In particular, you cannot use the desktop folder as the download
directory. On Linux, you also cannot use the home directory for
download. Since the exact list of forbidden directories is subject to
change, it is recommended that you use a directory that has no special
meaning to the system.
ChromeDriver does not automatically wait for download to complete. If you call driver.quit() too soon, Chrome might terminate before the
download has finished.
Relative paths do not always work. For best result, use full path instead.
On Windows, Use "\" as path separators. Using "/" is not reliable on Windows.
IF the manual does not work for you, try this one that works but isn't smart:
WebDriver driver = new ChromeDriver();
driver.get("chrome://settings/downloads");
// add some operation that change the default download directory

Having issues with firefox driver or chrome driver for selenium

For ex my chrome when dropped in the commpand prompt gives me the path
- /Applications/Google\ Chrome.app
I set
System.setProperty("webdriver.chrome.driver", "/Applications/Google/Chrome.app");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
But it doesnt work, same with firefox. I used a lot of suggestions already given but none seems to work. Can someone pls let me know if there is something to be added?
Why have you used "/Applications/Google/Chrome.app". You would need to provide the path of the driver only, not the browser. Below is the code for Firefox, but you would need to download and configure GeckoDriver (for latest version of FF and Selenium 3.x)
public class FirefoxTest {
#Test
public void FirefoxTest_Test1() {
System.setProperty("webdriver.gecko.driver","D:\\Firefox\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Check this link for complete details for downloading and setup of Geckodriver with Firefox - http://automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
For Chrome: Need to Download fresh Chrome Driver from http://chromedriver.storage.googleapis.com/index.html?path=2.24/
and mention local system path up to chomedriver.exe
System.setProperty("webdriver.chrome.driver","G:\\ravik\\Ravi-Training\\Selenium\\Drivers\\cd\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriver d1 = new ChromeDriver(capabilities);
For FF: if your firefox version is latest(46.0 or above) then user geckodriver along with selenium 2.53.0 jar files. download geckodriver form https://github.com/mozilla/geckodriver/releases and then save it as "wires" in your local system. mention local system path up to wires.
System.setProperty("webdriver.gecko.driver", "G:\\ravik\\Ravi-Training\\Selenium\\Marionette for firefox\\wires.exe");
WebDriver driver = new MarionetteDriver();
Hope this could be helpful.
The easiest way to use chrome driver is.. download and place the driver into the bin folder of your project. no need to set the path of the driver location

Java Selenium Chromedriver.exe Does not Exist IllegalStateException

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)

How do I setup the InternetExplorerDriver so it works

I am using WebDriver and I have downloaded the InternetExplorerDriver and was wondering what I do with it after it is downloaded?
This says to put the driver in my path. Not really certain what exactly they are talking about there.
Has anyone used this and if so could you provide detailed steps on how to set it up so it will work?
I am getting the following error:
The path to the driver executable must be set by the
webdriver.ie.driver system property
I downloaded the executables for IE and the Chrome driver. Where do I set it at?
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
Reference:
Driver executable must be set by the webdriver.ie.driver system property
If you are using RemoteDriver things are different. From http://element34.ca/blog/iedriverserver-webdriver-and-python :
You will need to start the server using a line like
java -jar selenium-server-standalone-2.26.0.jar -Dwebdriver.ie.driver=C:\Temp\IEDriverServer.exe
I found that if the IEDriverServer.exe was in C:\Windows\System32\ or its subfolders, it couldn't be found automatically (even though System32 was in the %PATH%) or explicitly using the -D flag.
Another way to resolve this problem is:
Let's assume:
path_to_driver_directory = C:\Work\drivers\
driver = IEDriverServer.exe
When getting messsage about path you can always add path_to_driver_directory containing driver to the PATH environment variable.
Check:
http://java.com/en/download/help/path.xml
Then simply check in cmd window if driver is available - just run cmd in any location and type name of driver.
If everything works fine then you get:
C:\Users\A>IEDriverServer.exe
Started InternetExplorerDriver server (32-bit)
2.28.0.0
Listening on port 5555
Thats it.
This is just to help somebody in future.
When we initiate InternetExplorerDriver() instance in a java project it uses IEDriver.exe (downloaded by individuals) which tries to extract temporary files in user's TEMP folder when it's not in path then ur busted.
Safest way is to provide your own extract path as shown below
System.setProperty("webdriver.ie.driver.extractpath", "F:\\Study\\");
System.setProperty("webdriver.ie.driver", "F:\\Study\\IEDriverServer.exe");
System.setProperty("webdriver.ie.logfile", "F:\\Study\\IEDriverServer.log");
InternetExplorerDriver d = new InternetExplorerDriver();
d.get("http://www.google.com");
d.quit();
public class NavigateUsingAllBrowsers {
public static void main(String[] args) {
WebDriver driverFF= new FirefoxDriver();
driverFF.navigate().to("http://www.firefox.com");
File file =new File("C:/Users/mkv/workspace/ServerDrivers/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driverIE=new InternetExplorerDriver();
driverIE.navigate().to("http://www.msn.com");
// Download Chrome Driver from http://code.google.com/p/chromedriver/downloads/list
file =new File("C:/Users/mkv/workspace/ServerDrivers/ChromeDriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driverChrome=new ChromeDriver();
driverChrome.navigate().to("http://www.chrome.com");
}
}
Basically you need to download the IEDriverServer.exe from Selenium HQ website without executing anything just remmeber the location where you want it
and then put the code on Eclipse like this
System.setProperty("webdriver.ie.driver", "C:\\Users\\juan.torres\\Desktop\\QA stuff\\IEDriverServer_Win32_2.32.3\\IEDriverServer.exe");
WebDriver driver= new InternetExplorerDriver();
driver.navigate().to("http://www.youtube.com/");
for the path use double slash //
ok have fun !!
Here is the exact solution, which worked in my case:
On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
System.setProperty("webdriver.ie.driver","C:\\Users\\ssin22\\Downloads\\IEDriverServer_x64_2.48.0\\IEDriverServer.exe");
package Testing;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class LaunchIE {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver","C:\\Users\\ssin22\\Downloads\\IEDriverServer_x64_2.48.0\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.get("http://google.com");
}
}
using System.Text;
...
..
static void Main(String[] args){
var driver = new InternetExplorerDriver(#"C:\Users\PathToTheFolderContainingIEDriver.exe");
driver.Navigate().GoToUrl("https://www.google.com/");
Console.Read();
}
You need not include the .exe file. The path to the folder containing the .exe worked for me
WebDriverManager allows to automate the management of the binary drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium WebDriver.
Link: https://github.com/bonigarcia/webdrivermanager
you can use something link this: WebDriverManager.iedriver().setup();
add the following dependency for Maven:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>x.x.x</version>
<scope>test</scope>
</dependency>
or see: https://www.toolsqa.com/selenium-webdriver/webdrivermanager/

Setup Chrome WebDriver with remote 'chromedriver.exe' file

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");

Categories

Resources