python – 如何在selenium中覆盖默认的chrome命令行开关集

python – 如何在selenium中覆盖默认的chrome命令行开关集,第1张

概述默认情况下,将使用此命令行运行chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"--disable-hang-monitor--disable-prompt-on-repost--dom-automation--full-memory-crash-report--no-default-browser- 默认情况下,将使用此命令行运行Chrome:

"C:\Program files (x86)\Google\Chrome\Application\Chrome.exe"--disable-hang-monitor--disable-prompt-on-repost--dom-automation--full-memory-crash-report--no-default-browser-check--no-first-run--disable-background-networking--disable-sync--disable-translate--disable-web-resources--safebrowsing-disable-auto-update--safebrowsing-disable-download-protection--disable-clIEnt-sIDe-phishing-detection--disable-component-update--disable-default-apps--enable-logging--log-level=1--ignore-certificate-errors--no-default-browser-check--test-type=ui--user-data-dir="C:\Users\nik\AppData\Local\Temp\scoped_dir1972_4232"--testing-channel=ChromeTestingInterface:1972.1--noerrdialogs--metrics-recording-only--enable-logging--disable-zero-browsers-open-for-tests--allow-file-access--allow-file-access-from-files about:blank

我需要覆盖(删除)所有命令–disable- *,因为没有等效的命令–enable- *.

最后,我想用这个命令行运行浏览器:

"C:\Program files (x86)\Google\Chrome\Application\Chrome.exe"    --dom-automation--full-memory-crash-report--no-first-run--safebrowsing-disable-auto-update--safebrowsing-disable-download-protection--enable-logging--log-level=1--ignore-certificate-errors--test-type=ui--user-data-dir="C:\Users\nik\AppData\Local\Temp\scoped_dir1972_4232"--testing-channel=ChromeTestingInterface:1972.1--noerrdialogs--metrics-recording-only--enable-logging--allow-file-access--allow-file-access-from-files about:blank

例如,我尝试使用翻译信息栏运行浏览器.
我找到了选项–enable-translate.

capabilitIEs = DesiredCapabilitIEs.Chrome.copy()capabilitIEs['Chrome.switches'] = ['--enable-translate']

但这并没有帮助,infobar没有出现.在命令行中,有两个命令: – disable-translate和–enable-translate.这是因为必须删除命令–disable-default-apps

解决方法 你应该自己开始浏览,然后告诉selenium,你已经通过传递特殊的频道ID启动了它.像这样的东西:

from random import randrangechannel_ID = "%032x" % randrange(16**32)from subprocess import Popen# HERE YOU PASS ONLY THOSE ParaMETERS YOU WANT (i.e. without --disable-*)# BUT YOU MAY NEED --dom-automation FOR SOME ROUTInesChrome = Popen(" ".join([    PATH_TO_Chrome_EXE,"--no-first-run","--dom-automation",("--testing-channel=\"namedTestingInterface:%s\"" % channel_ID),]))try:    from selenium.webdriver.Chrome.service import Service    Chromedriver_server = Service(PATH_TO_ChromeDRIVER,0)    Chromedriver_server.start()    from selenium.webdriver import Remote    driver = Remote(Chromedriver_server.service_url,{"Chrome.channel": channel_ID,"Chrome.NowebsiteTestingDefaults": True})    driver.get(MY_WEBPAGE)    # DO YOUR WORKfinally:    Chromedriver_server.stop()    driver.quit()Chrome.kill()Chrome.wait()
总结

以上是内存溢出为你收集整理的python – 如何在selenium中覆盖默认的chrome命令行开关集全部内容,希望文章能够帮你解决python – 如何在selenium中覆盖默认的chrome命令行开关集所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1192806.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存