Friday 19 February 2016

Click not working in Selenium Webdriver

Sometimes click method of selenium does not work. In such situations, you can use below solutions.
  1. Use javascript 
  2. Use Actions class
By using javascript, you can click on any element.

WebElement element = driver.findElement(By.linkText("Log in")); 
jsClick(element);

public static void jsClick(WebElement element){ 
 ((JavascriptExecutor) driver).executeScript
("arguments[0].click();",element);
 }

By using Actions, you can click on any element.

WebElement element = driver.findElement(By.linkText("Log in"));
clickByActions(element);

public static void clickByActions(WebElement element)
{ 
    Actions builder = new Actions(driver); 
    Action click = builder.click(element).build();
    click.perform(); 
}


What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books

Contributors