How to maximise the window in chrome browser in incognito mode using Selenium WebDriver? - selenium

How to maximise the window in chrome browser in incognito mode using Selenium WebDriver
I am using the below code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();
But in the last line code I am getting error as Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: No current window

To maximize the Chrome Browser in incognito mode you need to use the ChromeOptions class as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);

Related

How to Set capability for IE browser to run in Headless mode

I want to run the scripts in Headless mode for all the 3 browsers Chrome, Firefox & IE
The following is the code for Chrome:
System.setProperty("webdriver.chrome.driver", "./drive/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/");
Note : Its working fine
Firefox:
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "./drive/geckodriver.exe");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
driver.get("http://www.google.com/");
Note : Its working fine
IE:
Similarly i want to execute in IE with options
IE does not have support for a headless mode (since IE nowadays does not recieve any kind of update or improvements.).
But you can use trifle.js, a kind of browser that can emulate some IE versions in a headless mode, since its coded as a port of PhantomJS.

How to avoid username & password alert prompt (while authenticating proxy) in Selenium webdriver, chrome

How to avoid username & password alert prompt (while authenticating proxy) in Selenium webdriver, chrome?
System.setProperty("webdriver.chrome.driver","C:/Selenium/Chrome/chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Proxy proxy = new Proxy();
proxy.setHttpProxy("xx.xx.xxx.xx:yyyy");
proxy.setSslProxy("xx.xx.xxx.xx:yyy");
proxy.setSocksUsername("abcd");
proxy.setSocksPassword("efgh");
capabilities.setCapability("proxy", proxy);
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.get("https://abcd:efgh#whatismyipaddress.com/");
Try this,
System.setProperty("webdriver.chrome.driver", "G:/Chrome/chromedriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://abcd:efgh#whatismyipaddress.com/");

when I'm running my automation tests,I keep getting the "Disable Developer Mode Extension" in mobile emulation,I am using Chrome 2.21 driver

Here is the Sample code:
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//this line of code added to disable extension but still getting the alert capabilities.setCapability("chrome.switches", Arrays.asList("--disable-extensions"));
WebDriver driver = new ChromeDriver(capabilities);
How to disable this extension alert in mobile emulation mode?
If I add the below code,mobile emulation is not showing:
ChromeOptions options= new ChromeOptions();
options.addArguments("--disable-extensions");
How to disable this alert in mobile emulation mode using Selenium webdriver?
Try this...
ChromeOptions chop = new ChromeOptions();
chop.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(chop);

How to disable web security using selenium code for IE and Firefox

Written below code for chrome to disable web security
System.setProperty("webdriver.chrome.driver", "D:\\Eclipse\\chromedriver_win32\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
/*options.addArguments("test-type");
options.addArgument("--start-maximized");*/
options.addArguments("--disable-web-security");
/* options.addArguments("--allow-running-insecure-content");*/
capabilities.setCapability("chrome.binary","D:/Eclipse/chromedriver_win32/chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(options);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(options);
But I want to disable same for FF and IE.

What is the C# equivalent to Java ChromeOptions.setExperimentalOptions()?

I have automated android chrome browser with the below code:
DesiredCapabilities capabilities=DesiredCapabilities.chrome();
ChromeOptions options=new ChromeOptions();
options.setExperimentalOptions("androidPackage", "com.android.chrome");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver=new ChromeDriver(capabilities);
System.setProperty("webdriver.chrome.driver", "C://Users//Documents//Appium//ChromeDriver//chromedriver.exe");
String url="http://yahoo.com";
driver.get(url);
I am trying to automate android chrome browser using C# (Visual Studio) but can't find the equivalent code. I am using this but not working:
Capabilities = DesiredCapabilities.Chrome();
ChromeOptions options1=new ChromeOptions();
options1.AddAdditionalCapability("androidPackage", "com.android.chrome",);
Driver = new ChromeDriver(Chrome_Driver, options1);
I believe this is what you're looking for:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("androidPackage", "com.android.chrome");
driver = new RemoteWebDriver(new Uri("http://seleniumhubaddress:4444/wd/hub"), chromeOptions.ToCapabilities());