Reputation: 411
I'm using selenium web driver with Java language. when there are two buttons in a pop up i.e. ok and cancel , it can be easily handled with web driver using the following code:
Alert alert = driver.switchTo().alert();
alert.accept(); // or alert.dismiss(); depending upon the action u want to perform.
but what to do when there are more than two button, i.e. there are 3 to 4 buttons in the pop up ( e.g. like ok,cancel,try again, ignore/continue), in that case what do we do? how can we click on whichever button that we want?
Thank you very much for your help in advance
Upvotes: 1
Views: 5682
Reputation: 38424
What we're talking about are JavaScript's dialog popups. There's alert
(has an OK button), confirm
(has OK / Cancel) and prompt
(has an input field and OK). Nothing more. Therefore, the dialog you're seeing is not a JavaScript dialog and can't be handled by Selenium's Alert
interface.
You could be dealing with one of those two:
dialog()
(or something similar). That's good news! That's no real popup, that's just a well designed overlay consisting of normal HTML made to look like a dialog. You should be able to interact with this the usual way of WebDriver: inspect the elements with the tool of your choice, then find and click the button that needs to be clicked.Robot
class, it allows you to "press" programatically anything on the keyboard (or clicking blindly) and therefore getting rid of the dialog by, say, pressing EnterUpvotes: 2
Reputation: 935
You only want to use alert() when dealing with native browser popup dialogs. If the web app your testing pops up an HTML dialog then you can select and click on any of the buttons using the element ID, xpath, CSS selector etc.
Upvotes: 0