How do I setup the InternetExplorerDriver so it works - java

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/

Related

How to install plugin while launch the chrome browser?

I am using selenium,cucumber and java for automation testing.
I have a requirement of installing a plugin to the chrome browser to open my application. This plugin I have already installed. But when I open the chrome browser through selenium this plugin is missing and application is not working.
How to install the plugin each time when the browser is opening?
I'm using Chrome 65.0 and Selenium 3.11.0
Steps :
Run the following URL in Chrome: chrome://version/
Copy the Chrome profile path.
Open the Chrome profile path in Windows Explorer.
Open the Extensions folder (See the date and timestamp, when you installed that extensions)
Copy the folder path.
Code :
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", "F:\\Automation\\chromedriver.exe");
String pathToExtension = "C:\\Users\\USER_DELL_2014_07\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3\\Extensions\\bhlhnicpbhignbdhedgjhgdocnmhomnp\\2.0_0";
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=" + pathToExtension);
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
That's it! You can use this code and chrome would be instantiated with the given extension
Please let me know if you have any concerns related to this.

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

Selenium FireFoxDriver unable to connect

I've been attempting to use Selenium to drive Firefox for the fist time. I used virtually identical code to drive Chrome without issue. However, when I attempt to use the Firefox driver, the browser opens, stalls, and then, after about 60 seconds, I get an error report that reads as follows:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
4474-a285-3208198ce6fd}","syncGUID":"dcskEFBTLyBH","location":"app-global","version":"48.0.1","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\\Program Files\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1471881400240,"updateDate":1471881400240,"applyBackgroundUpdates":1,"skinnable":true,"size":21905,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"48.0.1","maxVersion":"48.0.1"}],"targetPlatforms":[],"seen":true}
1472056603181 addons.xpi DEBUG getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
I've checked other guides and all they recommend is that I update my .jar files. I am using selenium-java-3.0.0-beta2 and Firefox 48.0.1 to test so my files are up to date. I would like to get this to run properly.
UPDATE: code still does not work and I've set the System property to set the geckodriver properly. However, I still cannot get the driver to function properly. It won't even launch the browser any more.
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SimpleFireFoxDriver {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Selenium\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver();
driver.get("http://www.youtube.com");
System.out.println("Made it to the promised land");
driver.quit();
}
}
Edit: Also the path to FireFox itself is located here:
"C:\Program Files\Mozilla Firefox\firefox.exe"
Changing the system property worked for me. Change it to following:
System.setProperty("webdriver.firefox.marionette","src\\test\\java\\lib\\geckodriver.exe");
driver= new FirefoxDriver();
Hope that helps.
This is happening because you have set the wrong system property. You need to set system property as follows:
System.setProperty("webdriver.gecko.driver","C:\\Selenium\\geckodriver.exe");
Selenium firefox driver expects this System property to be set before initiating marionette driver and launching firefox. And if you don't set any System property and try to instantiate Firefox driver then you will get following error :
"The path to the driver executable must be set by the webdriver.gecko.driver system property."
Hope this helps.
Changing "webdriver.gecko.driver" with "webdriver.firefox.marionette" saved my life!
example:
Correct
System.setProperty("webdriver.firefox.marionette","C://selenium/gecko/geckodriver.exe");
Not correct
System.setProperty("webdriver.gecko.driver","C://selenium/gecko/geckodriver.exe");
Download the latest Gecko driver V0.17.0 and this resolved my error without changing the setProperty or downgrading of Firefox browser.
Not so sure, whether this may help you.
Changing "webdriver.gecko.driver" with "webdriver.firefox.marionette" saved my Life Also Downgrading Firefox from 50 to 36
Or try this code:
System.setProperty("webdriver.firefox.marionette", "D://Driver//geckodriver.exe");
WebDriver driver = new FirefoxDriver();

How to put file path of chromedrive on Eclipse

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

How to open chrome in Selenium webdriver?

I'm trying to launch chrome with Selenium Webdriver and used the following code:
System.setProperty("webdriver.chrome.driver",
"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.yahoo.com");
Chrome browser opens but is not proceeding further. What could be the reason for the following error:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
You are incorrectly starting up the driver
webdriver.chrome.driver is supposed to be the path to the driver that you've downloaded and not Chrome's physical location.
First you need to download chrome driver file from this link and than import its JAR to the package in eclipse.
Download the link from here
Then you will have to import it in your program.
import org.openqa.selenium.chrome.ChromeDriver;
and than make a driver instance
driver = new ChromeDriver();
Download the external JAR of chrome
In eclipse :: right click on the respective package(in the package explorer) and click on the properties. Go to Java build path and add external jars. Now add the jar file of chrome . and than follow the steps i wrote in the ans which was to import the chrome driver and creating an instance
Follow these steps in the photograph.
1)
select your file from here and right click
Below snippet shows how you can open chrome browser using selenium webdriver.
public static void main(String[] args) {
//Creating a driver object referencing WebDriver interface
WebDriver driver;
//Setting the webdriver.chrome.driver property to its executable's location
System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");
//Instantiating driver object
driver = new ChromeDriver();
//Using get() method to open a webpage
driver.get("https://stackoverflow.com");
//Closing the browser
driver.quit();
}
Use the latest versions of ChromeDriver.
Source|
http://chromedriver.storage.googleapis.com/index.html
You need to setup your browser settings first. Try below-mentioned code if it helps:
public void setup ()
{
System.setProperty("webdriver.chrome.driver", "C:\\**PATH**\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("--js-flags=--expose-gc");
options.addArguments("--enable-precise-memory-info");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-default-apps");
options.addArguments("test-type=browser");
options.addArguments("disable-infobars");
driver = new ChromeDriver(options);
driver.manage().deleteAllCookies();
}
You'll need to import files by hovering on error lines.

Categories

Resources