Button element found but click() action not performed



  • I am trying to verify close button using selenium java page object model. Close button is located in a pop up window. Below is the html code for the button.

    This is my function to check the close button

    public DataDetailViewPage validateCloseDetailPopup() {

      //find close button
      closePopUp = driver.findElement(By.cssSelector("button[type='button']"));
    

    //click button
    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("arguments[0].click()", closePopUp);

    //details pop up that visible after closing the detail card detailsPopup =
    driver.findElement(By.
    cssSelector("div[class='text-center justify-content-center']"));

    //click close button
    //closePopUp.click();

    //check if details pop up is present after closing the detail card
    Assert.assertTrue(detailsPopup.isDisplayed());

    //return new object of DataDetailViewPage
    return new DataDetailViewPage();
    }

    When I execute this function button click is not happening. I have not added a thread sleep since I perform other actions before clicking close. There are not any compilation issues as well.

    How can I click the close button?



  • Issue was there were more buttons with given css selector variables.So when executing selenium could not find the exact elements.

    The solution is to get all the elements with similar css variables and select specific element using get index and click that one.

    driver.findElements(By.cssSelector("button[type='button']")).get(13);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2