Wednesday

Challenges with different browsers in Selenium



The first thing you would do when you are picking to automate using Selenium WebDriver is launch a browser. Even this simple step can give you some glitches:

Firefox:

The most common issue is that the browser is invoked with unnecessary add-ins etc..
Simple solution:

Use the profile manager by typing the following command in run edit

"firefox.exe -p " to see all the profiles

Now use the profiling concept to avoid issues:

ProfilesIni all = new ProfilesIni ();
FirefoxProfile profile = all.getProfile("Profile Name")

WebDriver wd = new FirefoxDriver(profile);
ff.get("http://www.google.com");


//IE Driver

The most common issue here is that you get an error message regarding the trusted domains:
In Internet Options>>Security >>Trusted sites the Enable Protected Mode checkbox is unchecked currently. If we can check it manually the problem will be resolved.
The Reason of the issue is, the settings of IE are not as expected for Internet Explorer WebDriver API, so it can not find the HTML Document of the loaded application inside the Browser. 



Or use the below code:
 System.setProperty("webdriver.ie.driver", "C:\\Documents and Settings\\admin\\Desktop\\Selenium-Dump\\IEDriverServer.exe");
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

WebDriver wd = new InternetExplorerDriver(capab);
driver.get("http://www.google.com");

Or 


File file =new File("C:\\Documents and Settings\\admin\\Desktop\\Selenium-Dump\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
DesiredCapabilities cap= new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability("initialBrowserUrl", URL);                       //  this is the solution
cap.setJavascriptEnabled(true); 
driver=new InternetExplorerDriver(cap);



 //Chrome Driver
System.setProperty("webdriver.chrome.driver", "C:\\Documents and Settings\\admin\\Desktop\\Selenium-Dump\\chromedriver.exe");
 ChromeDriver cd = new ChromeDriver();





Happy Invoking :)




No comments:

Post a Comment