问题描述
Page Should Contain Button xpath = /html/body/blockquote/form/p/input
Click Button xpath = /html/body/blockquote/form/p/input
Confirm Action
"Confirm Action"关键字应该用于在警报框中选择确定",在上述情况下不会发生.我认为,Selenium2Library并未将下载框视为警报框,因为当我尝试获取警报消息时,我收到一条输出,提示未找到警报框".
The 'Confirm Action' keyword is supposedly used to select OK in an alert box, which is not happening in the above case. In my opinion, Selenium2Library is not treating the download box as an alert box, because when I tried Get Alert Message, I'm receiving an output saying 'No alert box found'.
我可以通过什么方式在下载框中选择确定"?同样,测试用例应仅取决于Selenium2Library关键字.不能使用外部Python API.
In what way can I select the OK in the download box? Also, the test case should be dependent on Selenium2Library keywords only. No external Python APIs can be used.
推荐答案
Selenium无法处理浏览器的下载框.一种解决方法是禁用下载弹出窗口.您必须创建一个库来设置Firefox设置和下载路径:
Selenium cannot handle the browser's download box. A workaround is to disable the download popup. You'll have to make a library which sets the Firefox settings and download path:
def create_profile(path):
from selenium import webdriver
fp =webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",path)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/plain") //the MIME type(s) for which you want to ignore the popup
fp.update_preferences()
return fp.path
然后将库导入测试套件中:
Then import the library in your testsuite:
*** Settings ***
Library | path/to/library
并在打开浏览器时设置Firefox配置文件:
And set the Firefox profile when you open the browser:
Open Browser | ${url} | ff | ff_profile_dir=path/to/download/folder
这篇关于使用Selenium2Library通过机器人框架处理mozilla firefox下载框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!