If your test case requires you to validate the text of a modal dialog, you can use the AutoIT function WinGetText.
1 2 3 |
Title = "message from webpage" IEText = ai.WinGetText(Title) puts IEText |
However, this method only works for IE modal popups. When using Firefox, the WinGetText function will output a nil. One possible solution around this is to highlight the text, copy it, send it to notepad, and then read it from there.
1 2 |
ai.WinActivate("A <a class="zem_slink" title="Modal window" href="http://en.wikipedia.org/wiki/Modal_window" rel="wikipedia">Modal Dialog</a>") site.button(:text, "OK").click |
#Focus on your main window and then initiate the modal dialog pop-up
1 |
ai.MouseClick("right", 660,370) |
#Center the mouse over the text you want to grab and right mouse click
1 2 |
ai.Send("a") ai.Send("^c") |
#Send the required key strokes to “Select All” and then copy (Ctrl + C)
1 |
ai.run("notepad.exe") |
#Open up notepad
1 2 |
ai.WinActivate("Untitled") ai.WinWaitActive("Untitled") |
#Activate and then wait for the notepad window to be active
1 |
ai.Send("^v") |
#Paste the copied text into notepad
1 2 |
dialogtext =ai.WinGetText(“Untitled”) puts dialogtext |
#Grab the notepad text and save it to a variable and then output the dialog text
1 2 3 4 |
ai.Send("!f") ai.Send("x") ai.WinWaitActive("<a class="zem_slink" title="Notepad (software)" href="http://en.wikipedia.org/wiki/Notepad_%28software%29" rel="wikipedia">Notepad</a>") ai.Send("n") |
#Close Notepad without saving
A quick video of the script detailed above:
The Modal Dialog shown in the video can be found at: http://www.phpguru.org/static/Modal-Dialog.html