Python Chromedriver,Selenium-自动下载
我将Selenium 2.43.0与Python 2.7.5结合使用。在某一点上,测试单击一个按钮,该按钮将表单信息发送到服务器。如果请求成功,服务器将以 1) 成功的消息 2) 合并了表单信息的PDF 我不想测试PDF,我的测试只是寻找一条成功的消息。但是,PDF是来自服务器的包响应的一部分,作为测试人员,我不能更改它 直到最近,使用Chromedriver时,这从来都不是问题,因为Chrome会自动将PDF下载到默认文件夹中 然而,几天前,我的一个测试环境开始弹出一个单独的窗口,显示pdf的“打印”屏幕,这使我的测试脱轨 我不想要或不需要这个对话框。如何使用chromedriver的选项以编程方式抑制此对话框?(相当于FireFox在Python Chromedriver,Selenium-自动下载,python,python-2.7,pdf,selenium,selenium-chromedriver,Python,Python 2.7,Pdf,Selenium,Selenium Chromedriver,我将Selenium 2.43.0与Python 2.7.5结合使用。在某一点上,测试单击一个按钮,该按钮将表单信息发送到服务器。如果请求成功,服务器将以 1) 成功的消息 2) 合并了表单信息的PDF 我不想测试PDF,我的测试只是寻找一条成功的消息。但是,PDF是来自服务器的包响应的一部分,作为测试人员,我不能更改它 直到最近,使用Chromedriver时,这从来都不是问题,因为Chrome会自动将PDF下载到默认文件夹中 然而,几天前,我的一个测试环境开始弹出一个单独的窗口,显示pdf的
about:config
中的pdfjs.disable
选项)
以下是我当前试图绕过该对话框的尝试,该对话框不起作用(通过“不起作用”不会禁用或抑制打印pdf对话框窗口):
两种测试环境中的所有组件版本都相同:
Selenium 2.43.0、Python2.7.5、Chromedriver 2.12、Chrome(浏览器)38.0.02125.122我不得不深入研究这一版本的内容——我找不到任何列出Chrome用户全套偏好的文档
关键是“plugins.plugins\u 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)
有趣的是,blanket命令chrome\u profile.add\u参数(“--disable plugins”)
开关并没有解决这个问题。但无论如何,我更喜欢外科手术。有些人设法打印成PDF:Docs
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)