Monday, January 16, 2012

How to start chrome browser using selenium webdriver?

For starting the chrome browser follow the instructions here - http://code.google.com/p/selenium/wiki/ChromeDriver

If you find it is difficult then dont worry just download the appropriate driver associated with your OS and then use the following code -

System.setProperty("webdriver.chrome.driver","path/to/chromedriver.exe");

It is the path to your downloaded chromedriver.exe

If you have a certificate warning for your product which uses https then use the following code -

       System.setProperty("webdriver.chrome.driver","path/to/chromedriver.exe");
        DesiredCapabilities dc = DesiredCapabilities.chrome();
        String[] options = { "--ignore-certificate-errors" };
        dc.setCapability("chrome.switches", Arrays.asList(options));
        return new ChromeDriver(dc);

Internet explorer is not starting using selenium webdriver. Message : Protected Mode must be set to the same value

If internet explorer is not starting using selenium webdriver and shows the error message says that "Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. "

Create a desired capabilities instance and use it while creating the internet explorer driver. This is what the configuration done for this error as per the docs in selenium wiki. selenium help wiki link - http://code.google.com/p/selenium/wiki/InternetExplorerDriver
Required Configuration

    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".
    The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.

Even if it does not start the browser, create a desired capabilities instance and set ingnore flakiness boolean to true. Here is the code for code for ignoring the the protected mode security for all zones.
   
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
 capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        WebDriver driver = new InternetExplorerDriver(capabilities);