如何使用 Robot Framework 捕获警告框
How to capture alert box using Robot Framework
我尝试截取警报屏幕截图,但屏幕上没有显示警报框。
例如:
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
有经验的可以帮帮我吗
据我了解,无法使用 SeleniumLibrary 捕获警报,因为警报不在页面的一部分。
我们通过使用 BuiltIn Screenshot 库和 KW Take Screenshot.
解决了这个问题
你可以试试看是否符合你的要求
您看到的行为是由于 Alert should be present
关键字自动接受警报。它发生得如此之快,以至于如果经常看起来它从未发生过。通过添加可选参数 action=LEAVE
,您可以在不修改行为的情况下进行检查。 Keyword documentation 显示其他选项。
*** 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
虽然这将解决您的:我没有看到问题的警报部分,但您将 运行 进入下一个。由于现在存在警报,使用 SeleniumLibrary 截屏将不起作用。如前所述,这可以由 Screenshot Library keyword Take Screenshot .
处理
请仔细阅读 Using with Python 部分,因为此库依赖于特定于操作系统的 Python 模块。
我尝试截取警报屏幕截图,但屏幕上没有显示警报框。
例如:
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
有经验的可以帮帮我吗
据我了解,无法使用 SeleniumLibrary 捕获警报,因为警报不在页面的一部分。
我们通过使用 BuiltIn Screenshot 库和 KW Take Screenshot.
解决了这个问题你可以试试看是否符合你的要求
您看到的行为是由于 Alert should be present
关键字自动接受警报。它发生得如此之快,以至于如果经常看起来它从未发生过。通过添加可选参数 action=LEAVE
,您可以在不修改行为的情况下进行检查。 Keyword documentation 显示其他选项。
*** 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
虽然这将解决您的:我没有看到问题的警报部分,但您将 运行 进入下一个。由于现在存在警报,使用 SeleniumLibrary 截屏将不起作用。如前所述,这可以由 Screenshot Library keyword Take Screenshot .
处理请仔细阅读 Using with Python 部分,因为此库依赖于特定于操作系统的 Python 模块。