Sawitree Cha
Sawitree Cha

Reputation: 199

How to capture alert box using Robot Framework

I try to capture alert screenshot but in the screen doesn't show alert box.

For Example:

AlertTest
    Open Browser    http://www.seleniummaster.com/robotframeworktest/alerttest.html    ff
    Sleep    5s
    Click Button    name=alert_button
    sleep    10s
    capture page screenshot
    Alert Should Be Present    This is an alert box
    Close Browser

If anyone has experience could you help me please.

Upvotes: 2

Views: 1652

Answers (2)

A. Kootstra
A. Kootstra

Reputation: 6961

The behavior you're seeing is due to the Alert should be present keyword automatically accepts the alert. It happens so fast that if often looks that it never happened. By adding the optional parameter action=LEAVE you can check without modifying the behavior. The Keyword documentation shows other options.

*** Settings ***
Library    SeleniumLibrary    

*** Test Cases ***
AlertTest
    Open Browser    http://www.seleniummaster.com/robotframeworktest/alerttest.html    chrome
    Sleep    2s
    Click Button    name=alert_button
    Alert Should Be Present    action=LEAVE    text=This is an alert box
    Handle Alert    action=ACCEPT
    Close Browser

Although this will solve your: I don't see the Alert part of the problem, you will run into the next one. Taking a screenshot using SeleniumLibrary will not work because of the now present Alert. As suggested earlier, this can be taken care of by the Screenshot Library keyword Take Screenshot .

Please read the Using with Python section carefully as this library depends on Operating System specific Python modules.

Upvotes: 0

akane
akane

Reputation: 449

To my understanding it is not possible to capture the alert with SeleniumLibrary, because the alert in not a part of the page.

We walk around this by using the BuiltIn Screenshot library and the KW Take Screenshot.

You could try and consider if it meet your requirements.

Upvotes: 4

Related Questions