Selenium IDE - How to handle java-script alerts an

2019-04-11 10:00发布

问题:

I am novice to automation testing and have started using Selenium IDE as the choice for automation.

I just want to know if there is any way to handle java-script alerts using IDE.

Take a scenario: I am clicking on "Delete" button and there comes a java-script alert box with OK and Cancel options, but Xpath can not identified for these elements.On the other hand, when I make a script for click event on delete button and run it using Selenium IDE, the element gets automatically deleted.

So, guys please help. Leave a reply in case my question needs to be elaborated.

Thanks in advance.

回答1:

Take a look at the documentation. The main part is this:

When running under Selenium, JavaScript pop-ups will not appear. This is because the function calls are actually being overridden at runtime by Selenium’s own JavaScript. However, just because you cannot see the pop-up doesn’t mean you don’t have to deal with it. To handle a pop-up, you must call its assertFoo(pattern) function. If you fail to assert the presence of a pop-up your next command will be blocked and you will get an error similar to the following

[error] Error: There was an unexpected Confirmation! [Chose an option.]

A step-by-step manual is in the section about Alerts.



回答2:

java-script alerts in ide can be handle using selenium commands storeAlert and

storeConfirmation what it will do is it Retrieves the message of a JavaScript confirmation or alert dialog generated during the previous action. this commands can be put at the position where the alert will occur

command:storeAlert

Target:variableName

command:storeConfirmation

Target:variableName

variable name is the variable in which the occurred alert will store

Thank you..