How to handle prompt box with Robot Framework?

不羁的心 提交于 2019-11-30 10:31:52

Selenium2Library doesn't currently have support for inserting text into a prompt. I've opened an issue in the issue tracker for this:

https://github.com/rtomac/robotframework-selenium2library/issues/292

Until it gets added, you can create your own selenium library by subclassing Selenium2Library, and you can add the function to your version.

For example, create a file named "CustomSeleniumLibrary.py", and make it look like this:

# CustomSeleniumLibrary.py
from Selenium2Library import Selenium2Library

class CustomSeleniumLibrary(Selenium2Library):
    def insert_into_prompt(self, text):
        alert = None
        try:
            alert = self._current_browser().switch_to_alert()
            alert.send_keys(text)

        except WebDriverException:
            raise RuntimeError('There were no alerts')

You can then write a test case which uses that library like this:

*** Settings ***
| Library | CustomSeleniumLibrary.py
| Suite Teardown | Close All Browsers

*** test cases ***
| Example of typing into a prompt
| | Open Browser | http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt
| | Select Frame | iframeResult
| | Click Button | Try it
| | Insert into prompt | my name is Inigo Montoya
| | Confirm action

Think it's worth pointing out that this keyword exists now (since SeleniumLibrary 3.0), so there's no longer any need to use a custom script/library. http://robotframework.org/Selenium2Library/Selenium2Library.html#Input%20Text%20Into%20Alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!