All of my tests are failing due to chrome opening up at a size of 800x600. I've looked at several sites for a solution, but nothing I've tried seems to be working.
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--window-size=1920,1080");
DesiredCapabilities cap = DesiredCapabilities.chrome();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setBrowserName("chrome");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
You apparently cannot resize the chrome in the headless mode .
If I am not mistaken.
"options.addArguments("--headless");"
I am also assuming you are using chromedriver
https://bugs.chromium.org/p/chromedriver/issues/detail?id=1625#c39
The -- is not needed for Java.
options.addArguments("window-size=1920,1080");
How to set the browser window size when using `google-chrome --headless`?
In selenium grid, i use the following code which is working for me.
ChromeOptions options = new ChromeOptions();
options.addArguments(Arrays.asList("--window-position=0,0"));
options.addArguments(Arrays.asList("--window-size=1840,1080"));
Related
I have a code that sets smaller windows of browser. If I create a Cucumber scenario with #mobile tag, what should I do next to open browser window in mobile view?
DesiredCapabilities mobileCapabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("no-sandbox");
options.setExperimentalOption("mobileEmulation", getMobileEmualtor());
mobileCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
I have this probleme i'am facing with an anti robot.
When i execute my code it works localy but when i use jenkins to execute it i get the anti robot shown in the web page i found out that the probleme is related to the option headless added into my chrome option once you add it the anti robot shows it happens on my computer too.
The probleme is that i cant remove the headless option because the execution is made on a server and without the headless option the execution fails.
Code localy :
ChromeOptions options = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.SEVERE);
options.setCapability("goog:loggingPrefs", logPrefs);
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\Driver\\chromedriver.exe");
options.addArguments("--headless", "--window-size=1920,1080");
options.setExperimentalOption("excludeSwitches", new String[] {"enable-automation"});
options.setExperimentalOption("useAutomationExtension", false);
//options.addArguments("--incognito");
driver = new ChromeDriver(options);
Code on the server :
String path = System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver", path+"/Driver/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu","--no-sandbox", "--window-size=1920,1080","--ignore-certificate-errors");
options.setExperimentalOption("excludeSwitches", new String[] {"enable-automation"});
options.setExperimentalOption("useAutomationExtension", false);
driver = new ChromeDriver(options);
Is there any solution i am missing ?
In Selenium, I am facing some issue when open browser in chrome then full screen is not working.
driver.manage().window().maximize();
driver.manage().window().maximize();
Replace to
driver.manage().window().fullscreen();
And it's working
As per manage().window().maximize() method not maximize a correct window using driver.manage().window().maximize(); to maximize the Chrome Browser is not the optimum way. Instead use ChromeOptions to maximize the Chrome Browser as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
To open Chrome Browser in kiosk mode you can also use:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
return new ChromeDriver(options);
As an alternative you can also use the argument window-size as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
I want to use portable google chrome for my selenium testing. I am using DesiredCapabilities object to set proxy in browser.
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
And for using portable Google chrome i am using this code.
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe");
driver = new ChromeDriver(options);
Now the problem is the constructor of ChromeDriver dont have option for creating driver object using both DesiredCapabilities as well as proxy. i.e. either i can apply proxy or i can use portable chrome.
I want something like this
new ChromeDriver(capabilities ,options);
I found a way
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
ChromeOptions options = new ChromeOptions();
options.setBinary("D:\\m_ali\\GoogleChromePortable\\GoogleChromePortable.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
System.setProperty("webdriver.chrome.driver", "D:\\m_ali\\chromeDriver\\chromedriver_2.27win32\\chromedriver.exe");
driver = new ChromeDriver(capabilities);
When I navigate to my url on chrome, I get The system cannot find the file specified." . I thought it might be due to automatic proxy settings on chrome.
I want to explicitly turn off the proxy setting before starting chrome browser in selenium. I tried below, it isn't working. Can anyone help me
ChromeOptions options = new ChromeOptions();
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability("chrome.setProxyByServer", false);
System.setProperty("webdriver.chrome.driver",sChromeDriverPath);
WebDriver driver = new ChromeDriver();
No errors are thrown at any point of time but URL doesn't open up
Tia
Anjana
You need to pass the options object to the chrome driver when you initialize it. If you use a specific capability then pass it to the chromeDriver(), so that chrome knows what to start with. Also there is no JSON object as setProxyByServer in chrome, instead use noProxy JSON object. Check this out. Here's how -
Proxy proxy=startProxy();
proxy.setProxyType(ProxyType.MANUAL);
proxy.setNoProxy("");
ChromeOptions options = new ChromeOptions();
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver",sChromeDriverPath);
dc.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(dc);
More info about chrome capabilities. Hope it helps.