Maximizing Safari window with selenium sometimes fails - selenium

I'm using Selenium RemoteWebDriver to run tests written in Java on a remote MacBook. I maximize the browser window using:
driver.manage().window().maximize();
This works 100% of the time for Chrome, Firefox and IE11. But with Safari this seems to fail about 30% of the time. I thought maybe there could be some extra synchronization issues with Safari so I tried:
Thred.sleep(10*1000);
driver.manage().window().maximize();
Thred.sleep(10*1000);
Unfortunately this did not help. I'm getting the error message:
TimeoutException: Timed out awaiting response to command "maximizeWindow"
Does anyone know how to solve this?
Edit: Since it might matter, here's the URL and Capabilities I'm using to create the driver:
DesiredCapabilities caps = DesiredCapabilities.safari();
LoggingPreferences logPrefs;
logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
RemoteWebDriver driver= new RemoteWebDriver(new URL("http://serverIP/wd/hub"), caps)

Related

chrome driver.manage().window().maximize() exception failed to change window state to maximized [duplicate]

The release notes for ChromeDriver 2.33 says that ""Fixes a bug which caused Resizing/Positioning Window commands to fail on Chrome 62+" however this still seems to be an issue when i am using Chrome 62+ browser. Maximizing chrome window using chrome driver results in below exception. Does anyone know a solution please?
Another thing i noticed is, though i installed latest chromedriver (v2.33) from https://chromedriver.storage.googleapis.com/index.html?path=2.33/, the log printed below says Driver info: chromedriver=2.25.426923 !!
Exception in thread "main" org.openqa.selenium.WebDriverException:
unknown error: cannot get automation extension from unknown error:
page could not be found:
chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=62.0.3202.62) (Driver info:
chromedriver=2.25.426923
(0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT
10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
There are exactly 2 issues.
As you mentioned, you have installed latest chromedriver (v2.33) but the log printed below says Driver info: chromedriver=2.25.426923, this issue must be addressed first. You can consider to manually kill all the dangling chromedriver.exe tasks from the Task Manager. Additionally you can consider to use CCleaner to wipe out all the rotten OS stuffs from your system. Take a system reboot if required. Finally ensure that what ever the absolute location of chromedriver.exe you are using within System.setProperty() ensure that the chromedriver binary is of version 2.33.
Finally, it is suggested to use ChromeOptions class to maximize the Web Browser as follows:
System.setProperty("webdriver.chrome.driver", "C:\\your_directory\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-infobars");
opt.addArguments("--start-maximized");
opt.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(opt);
driver.get("https://google.com");
Here are some of the alternatives which may solve your question:
Using maximize() from WebDriver.Window interface :
driver.manage().window().maximize();
Using setSize(Dimension targetSize) from WebDriver.Window interface:
driver.manage().window().setSize(new Dimension(800, 600));
Using addArguments("--start-maximized") through ChromeOptions:
chromeOptions.addArguments("--start-maximized");
Using addArguments("--window-size=1920,1080") through ChromeOptions:
chromeOptions.addArguments("--window-size=1920,1080");
Using executeScript() from JavaScriptExecutor interface:
((JavaScriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");
You can find a related discussion in Chrome - org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension at driver.manage().window().maximize();.
I believe there were some old chrome driver processes running in backend and same were being picked up when it was invoked via code. I deleted all processes instances, deleted old version of chrome driver, added the new 2.33 version and it worked. Thanks all for your suggestions.
I think the reason behind it may be your chrome version. Try again with updating your chrome browser. I have faced this type of issues for compatibility between chrome browser & the driver
Use class ChromeOptions.
System.setProperty("webdriver.chrome.driver", "h:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get(url);

Selenium FindElement and Chrome in Headless mode

After starting chromedriver.exe in headless mode following this advice and using just these arguments
options.AddArgument("headless");
options.AddArgument("window-size=1280,960");
The chromedriver opens invisibly. But Selenium's FindElement() command is not finding anything on the headless Chrome page. Instead it throws this exception:
An exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll but was not handled in user code
Additional information: no such element: Unable to locate element:
Q1: Has anyone had success running Selenium commands in Chrome's headless mode?
Q2: Have you been able to use FindElement with a chromedriver running in headless mode? If yes, how did you do it?
After reading more, perhaps something along these lines may be necessary? Add this to the Chrome startup options and then maybe connect chromedriver to it?
"remote-debugging-port=9222"
But with that option the IWebDriver and chromedriver does not open.
Background info: to answer, why would you want to do this? The primary reason was for tests run as a part of CI. These are tests that run on a VM and may not support 1080p monitors. If we ran it in headless mode and set the resolution that way we could.
Add below lines of code in your main class:
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.addArguments("--window-size=1920,1080");
options.addArguments("--disable-gpu");
options.addArguments("--disable-extensions"); options.setExperimentalOption("useAutomationExtension", false); options.addArguments("--proxy-server='direct://'");
options.addArguments("--proxy-bypass-list=*");
options.addArguments("--start-maximized");
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);

Unable to Execute Automation tests in opera browser

I try to use opera browser with selenium ,on running the scripts browser get launched but no tests are running in the browser instead a error popups. I am using operachromium driver with opera version 40
below is the code to create opera driver instance:
System.setProperty("os.name","windows");
System.setProperty("webdriver.chrome.driver", "path to operachromiumdriver");
driver = new ChromeDriver();
driver.get("http://google.com");
Can any one help me on this.

Remove security message using Selenium WebDriver with Java

While running Selenium automated tests on Chrome, I get following type of error message:
You're using an unsupported command line flag: ignore-certificate-errors. Stability and security will suffer
Can someone please suggest how can I remove it using Selenium WebDriver with Java?
Set mode "test-type" to ChromeDriver capabilities
Here's my sample code in Java
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type", "start-maximized",
"no-default-browser-check");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
If you are using chrome version 35.x, this kind of pop-up will come. Try using chrome version 34.x and then see.
Actually its the problem with chrome builds. Just give it a try.
Thank you,
Shravan Kumar.T

How to disable Flash in selenium remote webdriver

How do I disable the loading of flash objects when using Selenium Remote WebDriver.
It will be helpful if I get a solution for the normal webdriver also.
Since in most cases the Flash object is loaded by a JavaScript
I have tried disabling the javascript on the webdriver and remote webdriver both, but it does not work.
I tried to to disable the JavaScript by:
WebDriver driver = new FirefoxDriver();
((DesiredCapabilities) driver.getCapabilities()).setJavascriptEnabled(false);
I also tried:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(false);
WebDriver driver = new FireFoxDriver(caps);
For Remote WebDriver i tried:
final DesiredCapabilities firefoxCapability = DesiredCapabilities.firefox();
firefoxCapability.setJavascriptEnabled(false);
new RemoteWebDriver(new URL("http://" + windowsIP + ":4444/wd/hub"), firefoxCapability);
After execution of the above statement the remote server displays
Executing: [new session: <platform=ANY, javascriptEnabled=false, browserName=firefox, version=>] at URL:/session>
but still all the Javascript is executing on the pages the driver loads and the Flash is also loading.
Please help me :
1. how can stop the flash from loading.
2. need it on remote driver as I need to test the pages on IE, Firefox, Chrome. Hence loading the forefox profile will not work
Thank you for the help.
I used this code on Linux mint and it works:
FirefoxProfile profile= new FirefoxProfile();
profile.setPreference("plugin.state.flash", 0);
FirefoxDriver driver = new FirefoxDriver(profile);
though it's already answered question but on different forum... so i will consolidate for you...
I'm not sure if flash objects are loaded by javascript....but if disabling javascript is problem then...
Never disable Javascript for Firefox driver, in case if you want to use it being disabled try with HTMLUNITDRIVER which specially meant for non-javascript pages.
Reason being important parts of firefox driver is implemented in javascript and disabling would have serious concerns.
HtmlUnitDriver on the other hand is fastest and best way for automation tests (splly for pages with no JS)
please check this group discussion
https://groups.google.com/forum/?fromgroups=#!topic/webdriver/daLOzCiU_h4%5B1-25%5D
I had the same problem and needed it to be solved for Chrome. This is how I got it to work:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-bundled-ppapi-flash");
WebDriver webDriver = new org.openqa.selenium.chrome.ChromeDriver(options);