I'm using Selenium web driver with Java language. When there are two buttons in a popup 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 you want to perform.

But what to do when there are more than two buttons, i.e. there are 3 to 4 buttons in the pop up ( e.g. like ok, cancel, try again, ignore/continue)? How can we click on whichever button that we want?

  • I believe we have to use AUTOIT tool for it. Dec 23, 2012 at 16:37
  • Welcome to SQA, user1924504. Could you elaborate on this restriction? What factors cause you to use it? Is it the only option available, or are there other factors in your workplace that mandate it?
    – corsiKa
    Dec 24, 2012 at 17:10

2 Answers 2


You could probably use the sendkeys function from the alert class to either press the shortcut key to select the item you want or tab to the correct item and press enter. Unfortunately it doesn't seem like the Selenium Alert class allows you to click a specific item, which would be much more useful...

  • This seems to be a nice idea. Will try it out.
    – Tom
    Jul 9, 2012 at 7:23

Can you use the Selenium AdvancedUserInteractions?

Are you using CSS style sheets and/or page objects? It's very simple to select a single option from multiple choices using either of those and defining the buttons as WebElements.

element1.click() // (if you're using Java)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.