Sunday, 28 February 2016

How to launch a browser browser with out using system.setProperty() method in selenium

How to launch a browser browser with out using system.setProperty() method in selenium:
=====================================================================
For example take the IE browser.......
The very first issue anybody would face with IE Browser is that people expect IE Browser to work exactly like the Firefox Browser in Selenium. See what happens when you use the below Selenium Script to Open an application on IE Browser.
public class IEExplorerTest 
{

public static void main(String[] args) 
{

InternetExplorerDriver  driver = new InternetExplorerDriver();
driver.get(" http://rameshselenium.blogspot.in/");

}
}

Once the above code is executed, Selenium will throw an exception:

Exception in thread “main” java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html

The exception clearly says that the path to the driver must be set by the webdriver.ie.driver system property. This error typically is caused by either not having the required IEDriverServer.exe on your local machine or not having it setup in your PATH environment variable
How to set the path environment variable for IE Browser 
Open the Control Panel -> System or Security –> System; the same thing can be done by right-clicking on ‘My Computer’ and choosing Properties.

Choose ‘Advanced system settings‘.

 Under the Advanced tab Choose the ‘Environment Variable…‘ option.

Now we need to specify the location in the PATH variable. For PATH, most probably it already exists in your machine. So just select it and choose the Edit option.

In the editor add the value ‘Your Location of IE Browser‘(i.e: IE driver path which is downloaded) and click OK.

Note: The new values are separated by a semicolon from the existing ones and be careful and do not make any changes in the existing string, as it is very sensitive information.
Now try opening an IE Browser without specifying System Property in the Selenium        Script.

public class IEExplorerTest 
{

public static void main(String[] args) 
{

InternetExplorerDriver  driver = new InternetExplorerDriver();
driver.get(" http://rameshselenium.blogspot.in/");

}
}
Note: In case it does not work, please reboot the machine.
After executing above steps , still if we get the exception as 
 “java.lang.WebDriverException” 
           For the above write the code as below....
public class IEExplorerTest 
{

public static void main(String[] args) 
{
Try
{
InternetExplorerDriver  driver = new InternetExplorerDriver();
Thread.sleep(“2000”);
driver.get(" http://rameshselenium.blogspot.in/");
}
Catch(Exception e)
{
e.printStackTrace();
}

}

No comments:

Post a Comment