- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Running chrome browser in inconginto Mode in Selenium
We can run Chrome browser Incognito mode with Selenium webdriver. Incognito mode is a safe mode of opening a browser. This can be done with the help of the DesiredCapabilities and ChromeOptions class.
We shall create an object of the ChromeOptions class and apply addArguments method on it. Then pass −−incognito as a parameter to that method. We shall then create an object of the DesiredCapabilities class.
We shall apply setCapability method on the object of the DesiredCapabilities class and pass the ChromeOptions.CAPABILITY and the object of ChromeOptions class as parameters to that method.
Finally, this browser chrome profile shall be fed to the webdriver object.
Syntax
ChromeOptions o= new ChromeOptions(); o.addArguments("−−incognito"); DesiredCapabilities c = DesiredCapabilities.chrome(); c.setCapability(ChromeOptions.CAPABILITY, o); WebDriver driver = new ChromeDriver(o);
Example
import org.openqa.selenium.WebDriver; import org.openqa.selenium.Capabilities; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class BrwIncognt{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); // configure options parameter to Chrome driver ChromeOptions o= new ChromeOptions(); // add Incognito parameter o.addArguments("--incognito"); // DesiredCapabilities object DesiredCapabilities c = DesiredCapabilities.chrome(); //set capability to browser c.setCapability(ChromeOptions.CAPABILITY, o); WebDriver driver = new ChromeDriver(o); driver.get("https://www.tutorialspoint.com/index.htm "); } }
Output
- Related Articles
- Running Selenium WebDriver python bindings in chrome.
- How to launch Chrome Browser via Selenium?
- How to invoke the Chrome browser in Selenium with python?
- How to run Selenium tests on Chrome Browser using?
- How to avoid the pop-up window in chrome browser with Selenium?
- How to take care of SSL certificate issues in chrome browser in Selenium?
- Using the Selenium WebDriver - Unable to launch chrome browser on Mac
- How to open a link in new tab of chrome browser using Selenium WebDriver?
- Is there any way to load an extension in chrome browser using Selenium Webdriver?
- How to open browser window in incognito/private mode using python selenium webdriver?
- Running 8085 program in single-step mode
- How to Delete Bookmarks in your Browser (Firefox, Chrome)
- How to handle chrome notification in Selenium?
- Running javascript in Selenium using Python.
- Even in Offline Mode, You Can browse Using Google Chrome

Advertisements