启动Selenium Chromedriver时使用两个排除开关



我的目标是将Chrome作为一种在屏幕上显示全屏网页的服务。我正在通过创建一个python脚本来解决这个挑战,该脚本使用Selenium将chrome引导到正确的页面,并正确格式化网站。由于主要要求是显示器,因此显示的网页必须畅通无阻。在我的例子中,有两个障碍都可以通过使用不同的excludeSwitches选项来处理:

禁用自动栏:

chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);

要禁用"禁用开发者模式扩展"弹出窗口:

chrome_options.add_experimental_option("excludeSwitches", ['load-extension'])

然而,我还没有找到同时实现这两者的方法——我已经尝试过:

chrome_options.add_experimental_option("prefs", {"excludeSwitches": ['enable-automation'], "excludeSwitches": ['load-extension']});
prefs = {"excludeSwitches": ['enable-automation, load-extension'], "excludeSwitches": ['load-extension', 'enable-automation']}
chrome_options.add_experimental_option("prefs", prefs);

在这些情况下,根据顺序,只有其中一种具有预期效果。如何使我的语法正确以应用这两个选项?

测试代码(不包括进口(:

chrome_options = webdriver.ChromeOptions(); 
chrome_options.add_experimental_option("prefs", {"excludeSwitches": ['enable-automation', 'load-extension']})
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get(('https://www.google.co.uk'))

excludeSwitches是字符串的列表

chrome_options.add_experimental_option('excludeSwitches', ['load-extension', 'enable-automation'])

最新更新