4

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?

asked Jul 5, 2012 at 17:11
2
  • I believe we have to use AUTOIT tool for it. Commented 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? Commented Dec 24, 2012 at 17:10

2 Answers 2

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...

answered Jul 5, 2012 at 18:46
1
  • This seems to be a nice idea. Will try it out. Commented Jul 9, 2012 at 7:23
2

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)
element2.click()

etc.

dzieciou
10.5k9 gold badges49 silver badges102 bronze badges
answered Jul 10, 2012 at 20:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.