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.

Default Asked on November 4, 2014 in Selenium WebDriver.
on November 4, 2014.
Add Comment
  • 2 Answer(s)

    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.
    
    alert.accept();
    // Will click on Cancel button.
    
    alert.dismiss()
    
    

    Regards,
    Lakshay Sharma

    Professor Answered on November 4, 2014.
    Add Comment

    Dear lakshay,
    As what you said is right the modal is the part of the Html,but still i cant able to move to the search element in my modal.where i am using explicit wait((i.e)wait until Element to be Visible) to wait until the modal appears and also the search element in the modal to be visible.But i got the result as search element in the modal is not visible.

    Default Answered on November 4, 2014.

    Please paste the screenshot of the page, Modal window and HTML separately.

    Regards,
    Lakshay Sharma

    on November 5, 2014.
    Add Comment
  • Your Answer

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