Thursday, February 13, 2014

Java Script Executor in Selenium Webdriver

Sometime there is problem to click on hidden element. so to click on hidden element you can use java script as below:

 1. identify element through driver.findelement , suppose its name is element.


2. use below code it will perform click event on hidden element.


 ((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);

Wednesday, February 12, 2014

Multiple Browser Passing as Parameters

Multiple Browser Passing as Parameters


The Parameter "browser" is passed from TestNG.xml as below:



Then use the below code :

@Parameters("browser")
    @BeforeClass
    public void beforeTest(String browser) {
           if (browser.equalsIgnoreCase("firefox")) {
            FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
            driver = new FirefoxDriver(firefoxProfile);
           } else if (browser.equalsIgnoreCase("chrome")) {
                  // Set Path for the executable file
                  System.setProperty("webdriver.chrome.driver","D:\\Automation Project WorkSpace\\Experience\\lib\\chromedriver.exe");
                  driver = new ChromeDriver();
           } else if (browser.equalsIgnoreCase("ie")) {
                  // Set Path for the executable file
                  System.setProperty("webdriver.ie.driver", "D:\\Automation Project WorkSpace\\Experience\\lib\\IEDriverServer.exe");
                  driver = new InternetExplorerDriver();
           } else {
                  throw new IllegalArgumentException("The Browser Type is Undefined");
           }
           // Open App
           driver.get("https://www.google.com");
    }