RE: How to switch over to the Modal?

In our application i found some difficulties in switch over to the modal,is there any special functionalities for switch over of modals.

praveenkumar Default Asked on November 4, 2014 in Selenium WebDriver.
on November 4, 2014.
Add Comment
2 Answers

Hi Praveen,

If it is really a Modal Window, then you do not need to be use the switch command. Just get the id or xpath of it and do your operations on it. Modal window is always a part of same html page. Make sure you use the thread.sleep() before clicking any element on Modal window, as it is generated with the java script and sometime it takes one or more seconds to appear on the page but Selenium did not understand this delay, as it is a same page and it tries to perform action with in fractions of second and it got failed.
Example of modal window, most of the time it covers the background with transparent black wallpaper and on top it the window display.

If it is not Modal window and if it is a pop up alert try below code, this may help you.

// Get a handle to the open alert, prompt or confirmation

Alert alert = driver.switchTo().alert();
//Will Click on OK button.

// Will click on Cancel button.


Lakshay Sharma

Professor Answered on November 4, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.