Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium click not always working

I have some tests which click on a tab, however the click is not always performed.

  • The xpath is correct as most of the times the test works

  • It is not a timing issue as I ve used thread.sleep() and other methods to ensure that the element is visible before clicking

  • The test believes that it is performing the click as it is not throwing an ElementNotFoundException or any other exceptions when 'performing' the click. The test fails later on after the click since the tab content would not have changed.

Further Info I am using Selenium 2.44.0 to implement tests in Java which run on Chrome 44.0.2403.107 m.

Is there something else that I can do or could this be an issue with selenium?

like image 757
Jeremy Borg Avatar asked Jul 30 '15 13:07

Jeremy Borg


1 Answers

There are several things you can try:

  • an Explicit elementToBeClickable Wait:

    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    
    WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("myid")));
    button.click()
    
  • move to element before making a click:

    Actions actions = new Actions(driver);
    actions.moveToElement(button).click().build().perform();
    
  • make the click via javascript:

    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("arguments[0].click();", button);
    
like image 93
alecxe Avatar answered Oct 05 '22 11:10

alecxe