我想通过selenium在incongito
模式下运行chrome。
我用Google搜索了足够的内容,并在this link的帮助下找到了如何在incongito
模式下直接运行chrome:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" –incognito
但我没有得到如何在硒中运行它。
答案 0 :(得分:26)
在隐身模式下启动Chrome的另一种方法是添加参数“-incognito”,如下所示:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
此解决方案适合我。
答案 1 :(得分:9)
根据ChromeDriver wiki,您可以将参数传递给可执行文件,如下所示:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
WebDriver driver = new ChromeDriver(capabilities);
所以通过传感器 - 隐身应该可以解决问题。
答案 2 :(得分:5)
以下代码将使用selinium以隐身模式打开浏览器。假设在你的日食中设置了硒:
public WebDriver chromedriver;
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver chromedriver=new ChromeDriver(capabilities);
答案 3 :(得分:1)
当您将Selenium.WebDriver3.14.0与ChromeDriver 81搭配使用时,以下代码应可用。
ChromeOptions options = new ChromeOptions();
options.AddArgument("--incognito");
Driver = new ChromeDriver(options);
答案 4 :(得分:1)
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");
答案 5 :(得分:0)
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");
答案 6 :(得分:0)
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()