在Selenium中以inconginto模式运行chrome浏览器

k3fezbri  于 2022-12-06  发布在  Go
关注(0)|答案(8)|浏览(209)

我想通过selenium在incongito模式下运行chrome,我在谷歌上搜索了足够多的信息,找到了如何在this link的帮助下直接在incongito模式下运行chrome:
1.右键单击Google Chrome浏览器的快捷方式,然后选择“属性”。
1.在“目标”字段的“快捷方式”选项卡上,将-incognito添加到程序路径的末尾。因此,在“目标”字段中,您应该有"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" –incognito
但我不知道怎么用 selenium 来做。

px9o7tmv

px9o7tmv1#

另一种以incognito模式启动chrome的方法是添加参数“-incognito”,如下所示:

ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

这个解决方案对我很有效。

odopli94

odopli942#

根据ChromeDriver wiki,你可以像这样把参数传递给可执行文件:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
WebDriver driver = new ChromeDriver(capabilities);

因此,传递参数 *--隐姓埋名 * 应该可以做到这一点。

iszxjhcz

iszxjhcz3#

下面的代码将使用selinium以隐身模式打开浏览器。假设selenium已经在eclipse中设置:

public WebDriver chromedriver;
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver chromedriver=new ChromeDriver(capabilities);
xdyibdwo

xdyibdwo4#

当你使用Selenium.WebDriver3.14.0与ChromeDriver 81以下代码应该工作。

ChromeOptions options = new ChromeOptions();
options.AddArgument("--incognito");

Driver = new ChromeDriver(options);
cygmwpex

cygmwpex5#

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--incognito")

caps = options.to_capabilities()

browser = webdriver.Chrome(desired_capabilities=caps)
browser.get('https://amazon.in')

browser.quit()
n6lpvg4x

n6lpvg4x6#

System.setProperty("webdriver.chrome.driver", "path for chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("incognito");
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(cap);
    driver.get("webpage URL");
rm5edbpk

rm5edbpk7#

System.setProperty("webdriver.chrome.driver", "path for chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
driver.get("https://google.com");
bt1cpqcv

bt1cpqcv8#

from selenium import webdriver
baseUrl = ""
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
capability = options.to_capabilities()
driver = webdriver.Chrome(desired_capabilities=capability)
driver.get(baseUrl)

相关问题