admin管理员组文章数量:1278979
I am using Robot Framework with Selenium2Library for website tests automation. In one of the cases there is a prompt box (pop-up similar to alert, but with an input field in it, see example here) asking for some text. The problem is Robot Framework can only click OK or Cancel (Confirm Action and Choose Cancel On Next Confirmation keywords) on such pop-ups. So the question is: how can I input some text into the prompt box? Is it possible?
In SeleniumLibrary there was a Press Key Native keyword which could press keys without specifying the target element, but it is absent in Selenium2Library. If you know of any alternative - your answer will be much appreciated.
Using AutoIT isn't an option as the tests could be run on different platforms (not only Win).
Am I missing something?
I am using Robot Framework with Selenium2Library for website tests automation. In one of the cases there is a prompt box (pop-up similar to alert, but with an input field in it, see example here) asking for some text. The problem is Robot Framework can only click OK or Cancel (Confirm Action and Choose Cancel On Next Confirmation keywords) on such pop-ups. So the question is: how can I input some text into the prompt box? Is it possible?
In SeleniumLibrary there was a Press Key Native keyword which could press keys without specifying the target element, but it is absent in Selenium2Library. If you know of any alternative - your answer will be much appreciated.
Using AutoIT isn't an option as the tests could be run on different platforms (not only Win).
Am I missing something?
Share Improve this question asked May 8, 2014 at 13:48 IlliaIllia 1101 gold badge1 silver badge8 bronze badges2 Answers
Reset to default 5Selenium2Library doesn't currently have support for inserting text into a prompt. I've opened an issue in the issue tracker for this:
https://github./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./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/Selenium2Library/Selenium2Library.html#Input%20Text%20Into%20Alert
本文标签: javascriptHow to handle prompt box with Robot FrameworkStack Overflow
版权声明:本文标题:javascript - How to handle prompt box with Robot Framework? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741282099a2370065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论