简体   繁体   English

Chrome WebDriver 直接启动到 URL 而不是新标签页 - Python、Selenium

[英]Chrome WebDriver launch directly to URL instead of new tab page - Python, Selenium

I am trying to launch Chrome WebDriver using Selenium directly to a URL instead of launching to my default homepage (Chrome's new tab page) first and then calling driver.get(url) .我正在尝试使用 Selenium 直接将 Chrome WebDriver 启动到 URL 而不是首先启动到我的默认主页(Chrome的新标签页)然后调用driver.get(url) Is this possible?这可能吗?

I wasn't able to find a command-line argument to pass that would make the driver launch directly to a specified URL.我找不到要传递的命令行参数,它会使驱动程序直接启动到指定的 URL。 Does this command line argument exist?这个命令行参数是否存在?

I then tried to alter my homepage in the initialization of the driver via few different methods found online of adding a dict containing key 'homepage' and value 'desired_url' to the driver's "prefs", but none of these methods worked for me.然后,我尝试通过在线找到的几种不同方法在驱动程序的初始化中更改我的主页,这些方法将包含键'homepage'和值'desired_url'的字典添加到驱动程序的“prefs”,但这些方法都不适合我。

If there is no way to do this from the driver itself, how can I change my Chrome homepage from a Python program prior to launching the driver?如果无法从驱动程序本身执行此操作,如何在启动驱动程序之前从 Python 程序更改我的 Chrome 主页?

Thank you!谢谢!

--homepage= "url" --主页=“网址”

Command line argument命令行参数

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('homepage=url')
options.add_argument('no-startup-window') 
webDriver.Chrome(options=options)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM