Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
850 views
in Technique[技术] by (71.8m points)

testing - How can I press the alert ok button programmatically?

How can I press the OK button in a JS alert programmatically?

What I want to do: every time after the alert is created, the OK button is pressed.

This is for a UI test using Selenium RC.

Also, I have already checked: Click in OK button inside an Alert (Selenium IDE).

Edit: I had already used chooseOkOnNextConfirmation() and placed it before clicking the button the generated the alert. I also tried placing it after. Nothing worked!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Using chooseOkOnNextConfirmation you can do that.

selenium.chooseOkOnNextConfirmation();  // prepares Selenium to handle next alert
selenium.click(locator);
String alertText = selenium.getAlert(); // verifies that alert was shown
assertEquals("This is a popup window", alertText);

For more information, go through this link link


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...