【问题标题】:Handling mozilla firefox download box through robot framework using Selenium2Library使用 Selenium2Library 通过机器人框架处理 mozilla firefox 下载框
【发布时间】:2018-02-10 06:15:40
【问题描述】:
Page Should Contain Button xpath = /html/body/blockquote/form/p/input
Click Button xpath = /html/body/blockquote/form/p/input
Confirm Action
“确认操作”关键字应该用于在警告框中选择“确定”,但在上述情况下不会发生这种情况。在我看来,Selenium2Library 没有将下载框视为警报框,因为当我尝试获取警报消息时,我收到的输出显示“未找到警报框”。
如何在下载框中选择确定?此外,测试用例应该仅依赖于 Selenium2Library 关键字。不能使用外部 Python API。
【问题讨论】:
标签:
javascript
html
robotframework
selenium2library
【解决方案1】:
Selenium 无法处理浏览器的下载框。一种解决方法是禁用下载弹出窗口。您必须创建一个设置 Firefox 设置和下载路径的库:
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
然后在您的测试套件中导入库:
*** Settings ***
Library | path/to/library
并在打开浏览器时设置 Firefox 配置文件:
Open Browser | ${url} | ff | ff_profile_dir=path/to/download/folder