ChromeDriver in Fullscreen Mode - selenium

I am trying to send F11 to ChromeDriver, however it does not respond to it. When I press F11, it turns Chrome into fullscreen mode. When I send F11 through ChromeDriver, it does not. This is the same for any F-key in ChromeDriver. It works fine with FirefoxDriver and IEDriver, just not ChromeDriver. Is there any way I could get ChromeDriver into fullscreen mode ?
Note : Fullscreen mode is different from maximized mode, as it hides all toolbars.

I was able to solve it using kiosk mode, which keeps the browser in full screen
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
WebDriver driver = new ChromeDriver(options);

The argument is changed:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
Another option is change the startup script of google-chrome, set start-maximized as default.

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);
if you use RemoteWebDriver:
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Instance = new RemoteWebDriver(new URL(<SeleniumServerURL>), capabilities);

driver.manage().window().fullscreen();

In my case, i fix the differences between selenium webdriver coordinates and screen absolute coordinates (root cause: chrome tab, header and address field size are ignored by selenium .getcoordinate mechanism) by this way:
String shortcutGoToFullScreen = Keys.chord(Keys.F11);
WebDriver.findElement(By.tagName("body")).sendKeys(shortcutGoToFullScreen);
Only one problem, that this fullscreen mode became non full after any page code updates. So, it should be used carefully )

Use --start-fullscreen argument to Specify the browser should start in fullscreen mode, like if the user had pressed F11 right after startup.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);
You can change the behavior as you prefer by providing arguments to ChromeOptions.
Following link gives you in detail view of arguments and their behaviour. Hope it helps.
https://peter.sh/experiments/chromium-command-line-switches/#start-fullscreen

With Powershell/Selenium I wrote the script:
$Driver = Start-SeChrome -Fullscreen -StartUrl "https://........."
This worked perfectly for me

Related

selenium RemoteWebDriver opens but ChromeOptions are not passed to Selenium Grid

I have been trying to resolve a few issues with RemoteWebDriver and ChromeOptions using docker and selenium grid. The main issue is with the proxy but I half resolved that with a proxy pac file passing the pac file url as an arg into ChromeOptions. The below code runs great in docker debug and standalone locally but as soon as I try with the grid or deploy and run with bamboo the driver opens and I can see that ChromeOptions are not being passed because the poxy pac file is not being used and it's just frozen at org.openqa.selenium.remote.ProtocolHandshake createSession. I have been researching for a few weeks now and I am at a hard blocker with this now. I have seen some posts that DesiredCapabilities is deprecated but I have not found a way to implement ChromeOptions without it.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url= http://ProxyPacURL.com");
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
Update to latest Selenium Jars, make sure your java is version 1.8 or greater, then you can pass ChromeOptions into the driver because DesiredCapabilities is deprecated. I am now able to run selenium docker nodes with selenium grid and all ChromeOptions arguments are now being passed to the containers.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
I was facing same issue and I have found the solution as below:
We need to set "goog:chromeOptions" instead of "chromeOptions".
In your Java code, following line is present:
dc.setCapability(ChromeOptions.CAPABILITY, options);
If you navigate to ChromeOptions.CAPABILITY, you will notice that it is a constant with value "chromeOptions". This works fine for local web driver, but not for remote web driver (i.e. selenium grid).
Just change above line to this:
dc.setCapability("goog:chromeOptions", options);
Now when you execute your Java code, it will work fine and all your options will show their effect too.
I came across other pages, such as this, which referred to above solution.
Try this:
const GRID_HOST = 'http://localhost:4444/wd/hub';
var options = new chrome.Options();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new webdriver.Builder()
.usingServer(GRID_HOST)
.forBrowser("chrome")
.setChromeOptions(options)
.build()

Unable to find element on new tab link

When I run a browser with extension a pop up arise that says "Disable developer mode" to do so my script clicks on Disable, it opens a new tab with url "chrome://extensions/"
Now to click on checkbox of developer mode it always give an error "Unable to locate element."
driver.findelement(By.id("toggle-dev-on"));
http://prntscr.com/f8fbde
Here is the solution for your Question:
As per best practices to work with Selenium 3.4.0 you must download the latest chromedriver v2.29 from here, update your Google Chrome to 58.x.
Updating your chromedriver to v2.29 will solve your issue of Disable developer mode
To work with Google Chrome you can take help of ChromeOptions Class as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://gmail.com");
Let me know if this solves your Question.
You need to modify the appropriate browser profile to have JS disabled. Like for FireFox/Chrome you can tell Selenium which profile to use.
Chrome :
Map prefs = new HashMap();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
FireFox :
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("dom.webnotifications.enabled", false);
WebDriver driver = new FirefoxDriver(ffprofile);
Hope this will work out for your case.

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);

Selenium- Popup got blocked if I clicked Link using Javascript Executor in Chrome browser

Problem Description - Upon clicking a link on the page, popup got blocked automatically.
file = new File("tools/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
caps.setCapability("ignoreZoomSetting", true);
caps.setCapability("nativeEvents", false);
driver = new ChromeDriver(caps);
Environment used – Selenium WebDriver – 2.43.0 ChromeDriver, Windows 7
Note – it is working fine on Firefox & IE, this issue is happening on Chrome only.
Please assist on this.
This is a Chrome Option to disable all popups for the site
Open Chrome.
Find a page that has pop-ups blocked for you.
At the end of the address bar, click the pop-up blocker icon chrome op-up
locked.
Click the link for the pop-up window you'd like to see.
To always see pop-ups for the site, select Always show pop-ups from [site].
Once you have this set use the profile it is saved against to load for the test
Another option is to open the site and Shift F5 to do a Cache Refresh
Load a Profile. The code below is C# and you haven't specified a language. Please see the links provided for Java examples
ChromeOptions options = new ChromeOptions();
userDataPath = "C:/Users/user_name/AppData/Local/Google/Chrome/User Data";
options.AddArguments("user-data-dir=" + userDataPath);
options.AddArguments("--start-maximized");
driver = new ChromeDriver("pathToChromeDriver", options);
You can pass the chromeOption to allow pop-up as shown in below:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.popups", 1);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);

chromedriver full screen doesn't work on Linux

I am trying to start Chrome browser in full screen mode (similar to using F11) on Ubuntu 12.04. I am using the following code, but this doesn't see to work:
if (browser.equalsIgnoreCase("chrome")) {
//Set full screen mode (similar to F11)
ChromeOptions options = new ChromeOptions();
options.addArguments("start-fullscreen");
//Create a new Chrome Driver
System.setProperty("webdriver.chrome.driver","./lib/chromedriver");
this.driver = new ChromeDriver(options);
}
I am using Chrome version 34 with WebDriver version 2.41. Any suggestions?
Linux Mint 16, Chrome version 34.0.1847.132, Selenium 2.41.
Full screen mode works fine.
Try to use:
driver.manage().window().maximize();
to maximize browser window.
Edited.
Also you can try to run chrome in kiosk mode:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
driver = new ChromeDriver(options);
This works fine in Linux with Chrome 34.
Or try to press F11 like:
driver.findElement(By.tagName("html")).sendKeys(Keys.F11);
But for me it works fine only in Firefox.
If you're trying to send F11 to the browser, you can probably do it this way:
driver.FindElement(By.TagName("html")).SendKeys(Keys.F11);