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.

<div class="webModal__CloseButtonRow-hOUtMR dNkjlk"><button class="MuiButtonBase-root-3058 MuiIconButton-root-3688 jss3598 MuiIconButton-colorPrimary-3692" tabindex="0" type="button"><span class="MuiIconButton-label-3695"><svg class="MuiSvgIcon-root-3008 jss3599 MuiSvgIcon-fontSizeSmall-3015" focusable="false" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z"></path></svg></span></button></div>

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 =
  cssSelector("div[class='text-center justify-content-center']"));
  //click close button 
  //check if details pop up is present after closing the detail card
  //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?

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.