Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accept an alert using robot framework

Using selenium2library to automate my web application with robot framework. I am not able to accept a browser alert using the existing keywords.

Getting the below exception while trying to accept the alert.

UnexpectedAlertPresentException: Alert Text: Delete selected trusted provider(s)?
<super: <class 'WebDriverException'>, <UnexpectedAlertPresentException object>>

have tried the below selenium2library keywords Alert Should Be Present, Get Alert Message , Confirm Action, etc.

Please guide me on how to proceed.

like image 951
user3036030 Avatar asked Oct 23 '14 04:10

user3036030


People also ask

How does Robot Framework handle alerts?

How to Handle Javascript Alert, Confirm and Prompt in Robot Framework. Javascript Confirm: It will have some text with 'OK' and 'Cancel' buttons. Javascript Prompt: It will have some text with a text box for user input along with 'OK' and 'Cancel' buttons. – Handle JS Alerts: Test Case Name.

How do you get text in Robot Framework?

You just have to identify the stop point, which in your example looks like it would be the hyphen between the two number values. for example: to extract the last five digits of this string ABC12345 you would want to create a variable to assign the text to.


2 Answers

At last I have found a way to handle alerts in Robot Framework.

We just have to use "Choose Ok On Next Confirmation" with "Confirm Action" Keyword.

Say if I want to accept an Alert prompting for Yes or No for deleting an resource using selenium you can use the below code.

Choose Ok On Next Confirmation      
Click Element   //a[contains(.,'Delete')]
Confirm Action  

This will be accepting the Alert. If you want to dismiss or deny the alert you can simply use the keyword Alert Should Be Present which will auto dismiss the alert.

like image 80
user3036030 Avatar answered Oct 19 '22 22:10

user3036030


As of Selenium2Library 3.0 you can use the Handle Alert keyword with the actions:

  • ACCEPT: Accept the alert i.e. press Ok. Default.
  • DISMISS: Dismiss the alert i.e. press Cancel.
  • LEAVE: Leave the alert open.

There is also an optional 2nd argument that you can use to supply a timeout. It is also possible to store the text from the alert in a variable.

Handle Alert Keyword - Selenium2Library Docs http://robotframework.org/Selenium2Library/Selenium2Library.html#Handle%20Alert

like image 43
Phil Quarrell Avatar answered Oct 19 '22 23:10

Phil Quarrell