dbJ*_*nes 3 python pdf selenium python-2.7 selenium-chromedriver
我正在使用Selenium 2.43.0和Python 2.7.5.有一次,测试点击了一个按钮,该按钮将表单信息发送到服务器.如果请求成功,则服务器响应
1)成功的消息
2)合并了表单信息的PDF
我不关心测试PDF,我的测试只是寻找成功的消息.然而,PDF是服务器的包响应的一部分,作为测试者,我无法更改.
直到最近,使用Chromedriver这一直不是问题,因为Chrome会自动将pdfs下载到其默认文件夹中.
但是,几天前我的一个测试环境开始弹出一个单独的窗口,其中包含pdf的"打印"屏幕,这会破坏我的测试.
我不想要或不需要这个对话框.如何使用chromedriver的选项以编程方式禁止此对话框?(相当于FireFox pdfjs.disable
选项的东西about:config
).
这是我目前试图绕过对话框的尝试,该对话框不起作用("不工作"不禁用或禁止打印pdf对话框窗口):
dc = DesiredCapabilities.CHROME
dc['loggingPrefs'] = {'browser': 'ALL'}
chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "C:\\SeleniumTests\\PDF",
"download.prompt_for_download": False,
"download.directory_upgrade": True}
chrome_profile.add_experimental_option("prefs", profile)
chrome_profile.add_argument("--disable-extensions")
chrome_profile.add_argument("--disable-print-preview")
self.driver = webdriver.Chrome(executable_path="C:\\SeleniumTests\\chromedriver.exe",
chrome_options=chrome_profile,
service_args=["--log-path=C:\\SeleniumTests\\chromedriver.log"],
desired_capabilities=dc)
Run Code Online (Sandbox Code Playgroud)
两个测试环境中的所有组件版本都相同:
Selenium 2.43.0,Python 2.7.5,Chromedriver 2.12,Chrome(浏览器)38.0.02125.122
dbJ*_*nes 12
我不得不深入研究这个源代码 - 我找不到任何列出全套Chrome用户首选项的文档.
关键是 "plugins.plugins_disabled": ["Chrome PDF Viewer"]}
完整代码:
dc = DesiredCapabilities.CHROME
dc['loggingPrefs'] = {'browser': 'ALL'}
chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "C:\\SeleniumTests\\PDF",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.plugins_disabled": ["Chrome PDF Viewer"]}
chrome_profile.add_experimental_option("prefs", profile)
#Helpful command line switches
# http://peter.sh/experiments/chromium-command-line-switches/
chrome_profile.add_argument("--disable-extensions")
self.driver = webdriver.Chrome(executable_path="C:\\SeleniumTests\\chromedriver.exe",
chrome_options=chrome_profile,
service_args=["--log-path=C:\\SeleniumTests\\chromedriver.log"],
desired_capabilities=dc)
Run Code Online (Sandbox Code Playgroud)
有趣的是,毯子命令chrome_profile.add_argument("--disable-plugins")
开关没有解决这个问题.但我更喜欢更多的手术方法.
归档时间: |
|
查看次数: |
7713 次 |
最近记录: |