Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I handle modal dialogs with selenium 2

I have a link that opens a modal dialog

How can Selenium 2 handle this.

Thanks

Aidan

like image 208
Aidan_Mc_Donnell Avatar asked Nov 22 '10 15:11

Aidan_Mc_Donnell


People also ask

How will you deal with the dialog box in windows using Selenium?

Selenium uses the getWindowHandles () and getWindowHandle () methods to work with child windows. The getWindowHandles () method contains all the window handle ids of the opened windows. The window id handles are held in the form of Set data structure [containing data type as String].

What is the difference between a modal and a dialog?

Modals prevent access to the main pageWhile a modal dialog is active a user cannot interact with the main page and is restricted to only the information in the modal for making decisions. Modal tasks should be easy to complete with the limited information presented in the dialog itself.


1 Answers

With selenium 2 , I'm able to select elements in a jquery modal dialog using the normal "findElement" method.

e.g. the following code in c#

[Test]
    public void DialogBox()
    {
        var driver = new FirefoxDriver();
        driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 20));
        driver.Navigate().GoToUrl("http://example.nemikor.com/basic-usage-of-the-jquery-ui-dialog/");
        // open modal dialog
        driver.FindElement(By.Id("opener")).Click();
        // click a button on the modal dialog.
        driver.FindElementByClassName("ui-icon ui-icon-closethick").Click();

    }
like image 65
Matthew Kelly Avatar answered Oct 05 '22 22:10

Matthew Kelly