Run chrome browser in inconginto Mode in Selenium

前端 未结 7 1594
忘掉有多难
忘掉有多难 2020-12-02 21:11

I want to run chrome in incongito mode through selenium. I googled enough for it and found how to run chrome directly in incongito mode with the h

相关标签:
7条回答
  • 2020-12-02 21:41
    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()
    
    0 讨论(0)
  • 2020-12-02 21:44

    When you use Selenium.WebDriver3.14.0 with ChromeDriver 81 bellow code should work.

    ChromeOptions options = new ChromeOptions();
    options.AddArgument("--incognito");
    
    Driver = new ChromeDriver(options);
    
    0 讨论(0)
  • 2020-12-02 21:45

    The code below will open the browser in incognito mode using selinium. Assuming selenium is setup in your 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);
    
    0 讨论(0)
  • 2020-12-02 21:46

    One other way to launch chrome in incognito mode is to add argument "-incognito" like following:

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

    This solution works for me.

    0 讨论(0)
  • 2020-12-02 21:50

    According to the ChromeDriver wiki you can pass parameters to the executable like this:

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

    So passing the paremeter --incognito should do the trick.

    0 讨论(0)
  • 2020-12-02 21:54
        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");  
    
    0 讨论(0)
提交回复
热议问题