Press the OK button on a popup window using Selenium

I'm trying to click on the "OK" button in a modal alert, but for some reason I can't seem to make it work.

// Capturing alert message.    
String alertMessage= driver.findElement(By.className("modal-header"))
                           .getText();

System.out.println(alertMessage);


String okButton= driver.findElement(By.xpath("//h4[contains(text(),'Woo Hoo! You have successfully registered! Look ou')]"))
                       .getText();
System.out.println(okButton);

driver.findElement(By.xpath("//button[contains(text(),'OK')]"))
      .click();

Despite trying the above code, it's not functioning as expected. The error message I'm receiving in the console is:

: unknown error: Element

<button type="button" class="close" ng-click="goTOLogin()">...</button>
is not clickable at point (897, 161). Other element would receive the click:
<div class="loader" style="display: block; opacity: 0.681626;"></div>

This is the relevant HTML code snippet:

<div id="registration" class="modal fade ng-scope in" role="dialog" style="display: block;">
  <div class="modal-dialog modal-md add-brand">
    <!-- Modal content-->
    <div class="modal-content flat-modal">
      <div class="modal-header">
        <button type="button" class="close" ng-click="goTOLogin()">X</button>
        <h4 class="modal-title common-title" style="" xpath="1">successfully registered</h4>
      </div>
      <div class="modal-body flat-body">
        <div class="clearfix"></div>
        <h4>Woo Hoo! You have successfully registered! Look out for the activation link in your email.</h4>
        <div class="modal-footer text-left">
          <button type="button" class="close" ng-click="goTOLogin()" style="">OK</button>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

To accept alerts, simply press the enter key.

Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining Spring Boot with React Using Material UI Design

Currently in the process of setting up a Spring Boot project (Prototype) using React and Material UI. To kick things off, I utilized this tutorial to successfully get Spring Boot functioning with React. Moving on to implementing Material UI, I followed st ...

Guide on how to use Selenium to drag and drop a canvas web element specifically in the Chrome browser

Having trouble moving an image within the canvas web element (avatar editor) on Chrome using Selenium. Check out this canvas element: Watch a quick demo of what I'm trying to accomplish with Selenium Webdriver: Please review the code snippet below. ...

I keep encountering a "map is not a function" error while working with React JS

I am attempting to retrieve and display data from a MySQL database using Spring Boot and React JS in a table format. However, I am encountering an error while trying to display the information. componentDidMount(){ const currentUser = AuthService.g ...

Developing React applications using Behavior Driven Development with a personalized API call for simulating mock

Currently, I am utilizing BDD with cucumberjs, selenium-webdriver & react. Within a specific scenario, I wish to execute a Mock API call rather than an actual API call. For instance, I am currently making a call to: http://example.com/v1/getData However ...

React-Collapsible Compilation Error

Currently, I am working on a project that involves Spring and ReactJS. I am still new to front-end development. One of the tasks I am trying to accomplish is creating a simple accordion using "REACT-COLLAPSIBLE". The code I have written is quite straight ...

Initiate a react change event using Appium

I'm currently working on automating a hybrid app that has a login screen implemented as a react web view, and unfortunately, I don't have control over it. The challenge I'm facing is that the Sign-in button remains disabled until something i ...

There was a critical error during compilation: java.lang.Il legalAccessError. It appears to be stemming from the class lombok.javac

Even after installing Lombok, updating Java, and setting all necessary System Variables for Maven and JAVA_HOME, I still encounter an error. The POM builds fine and all essential files like mvnw and mvnw.cmd are functioning properly. However, when attempti ...