Bring the IE Browser to Front/focus - java

I am testing a platform with Selenium and IE 11 Using IE Driver 3.0.0.
Windows 10 Pro
Java JDK 1.8.0_25
As for my research, I tried this:
String currentWindow = driver.getWindowHandle();
driver.switchTo().window(currentWindow);
And with JavaScript, I also tried this. (See first answer)
Is there any way I can bring the IE window that selenium opens and bring it to front/focus it? Since I use a robot at one point to perform a few actions, I need the browser to be on focus automatically, otherwise my robot actions are not effective.

((JavascriptExecutor) driver).executeScript("window.focus()");

Related

Selenium Automation on IE11 (Enterprise mode)

I have installed Enterprise mode on IE11 to support applications which are only run on lower version of IE.
Using Enterprise mode on, to support application adhered to IE10 only I started scripting.
I am successfully able to traverse few pages but at one particular sidebar I am not able to click element.
It gets highlighted using javascript which means I find the element. But I am not able to click the element. it gets dotted square around the element.
I don't get any exception on that line.
There are no frames issue.
P.S: One of the post stated that there might be an issue with unexceptional behaviour of Tomcat. Due to which I find element but click() event does not work.
Try:
element.sendKeys(Keys.ENTER);
If not working try:
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

Native events behaves differently on different versions of firefox with selenium

Earlier I was using Firefox 25.0.1 and Selenium 2.42.2 to test my web-app. It consists of a menu tab, hovering over which gave sub menus and then I have to click on one of the sub menus. I was using following code:
Actions actions = new Actions(getFFWebDriver());
Action action = actions.moveToElement(getFFWebDriver().findElement(By.id("main.menu"))).build();
action.perform();
getWebDriver().findElement(By.xpath("//*[#id=\"submenu\"]/span")).click();
But when I upgraded my browser to version 28 it doesn't work like , it used to.
I also tried upgrading selenium version to 2.46, still it doesn't work like as it used to with selenium 2.42 and FF-25.
Any help would be appreciated.
Native event support for firefox webdriver tend to be for a few specific versions of the browsers for each release of selenium. I suspect your versions of selenium doesn't support native events in firefox 28.
The changelog for V2.42 doesn't say what version of firefox they support for native events but apparently V28 of firefox was supported in V2.41. You could always try downgrading to that version of selenium or try firefox 33 on selenium V2.46 which looks like the latest version of firefox that has native event support.
https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG
There is also the option of going for synthetic events over native events.
For me it works like this:
WebElement menu = driver.findElement(men);
Actions builder = new Actions(driver);
builder.moveToElement(menu).moveToElement(driver.findElement(submenu)).click().build().perform();
This works even i upgrade FF 25 -> 30 and also works well on Chrome.

Using pre opened window with Selenium

I am trying to get Selenium WebDriver to find and use a browser window that is already open before the script executes. I am writting in Java.
I am using selenium-server 2.37.0 and the browser is IE8. I am open to using the Chrome browser as well.
Anyway, I have tried opening a driver instance and then looking for the window handles in the usual way (Set handles = driver.getWindowHandles();) but this only finds the hadle of the window that the driver opened. I have also just tried to switchTo the window by the window cannot be found.
The reason I want to use a pre-opened window is because when I execute my script, for some reason the browser won't let it click a link (It may be because the link is to an https address and sends a username and a token). When the script finishes the webpage won't respond to me manually clicking the link either.
I am able to manualy navigate to the link and click it the link works fine, so my thinking is that I can navigate to the page that I want and then kick of the scripts from there, but I need the webdriver to use this browser window that I used.
I cannot navigate the to link directly with Selenium because the link resided behind a secure server. I have to log in first then click the link and this is where I am having the problem.
Unfortunately, as of 2.37.1 (December 2013), it cannot be done.
There is an official feature request for this in the Selenium project (and it's even the most starred one), but it has not been done yet.
You can identify a browser window by windowHandle and switch between several Windows while testing.
You can print out all existing windowHandles (in your case it might be one) and then access it.
This solution worked for me (using Selenium 3.4.0):
Object[] handles = driver.getWindowHandles().toArray();
String windowHandle = handles[0]+"";
driver.switchTo().window(windowHandle);
After switching to your browser window you should be able to continue your test.
It relys on correctness of your webdriver- if you opened an Edge window the driver you use should be an EdgeDriver.

How to quit webdriver, while browser already closed by application

I'm testing web application with Selenium Webdriver (IE). After signing off, application closes the browser, but quiting the webdriver cause crash popup for IEDriverServer.exe which hangs the flow.
Is there's a way to unload the IEDriverServer.exe after browser was closed?
You can handle this in various ways. One logic i can think of is to do getWindowHandles() and call driver.quit() based on the window count. In your case after logoff it will be null.
I had this problem with an earlier version, which version are you using? There may be a newer version of IEServerDriver than what you have. I placed mine in a directory that I then added to system PATH and have no troubles with Chromedriver or IEServerDriver.
Don't know exact solution but, for Workaround, you can try this out :
use driver.close()
If first option doesn't work then open the browser once again and use driver.quit() or driver.close().

Does Selenium WebDriver support Safari?

I'm using Selenium WebDriver with Java. I want to use Safari browser. Does Selenium WebDriver support Safari?
Experimental support of Safari was added in Selenium recently. See https://code.google.com/p/selenium/wiki/SafariDriver
The SafariDriver is still experimental and relies on a browser plugin using WebSockets to communicate to the browser. It's a great step and it's something that many have been waiting for.
However, if you want something a bit more stable, Darrel Grainger has a good post on how to instantiate a Webdriver object utilizing the Selenium RC (a.k.a Selenium 1) API.
It's probably the best way to get Safari testing going right now.
Refer latest post here by Apple:
https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari
Yes, webdriver will support Safari. following instruction https://code.google.com/p/selenium/wiki/SafariDriver
As of Safari 10, there is now a native support for WebDriver API. More info here https://webkit.org/blog/6900/webdriver-support-in-safari-10/
You can see the Selenium Java API doc:
http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html
There are detail of Class SafariDriver
All these answers were out of date for me. I had to track down and find the latest ... it's located here :
http://elementalselenium.com/tips/69-safari
Download for the driver is
http://docs.seleniumhq.org/download/
Short and precise answer is YES.
Selenium 3 supports Safari 12 in a well mannered way. It's pretty much stable for automation testing.
I am using Selenium v3.141.59 with Safari v12.1.2 flawlessly.
With Selenium 3, you don't need to download/install SafariDriver explicitly; instead you just need to enable the built in SafariDriver comes with MacOS.
Web driver does support safari with the help of crome driver.
please see this
http://seleniumhq.org/docs/03_webdriver.html#selenium-webdriver-s-drivers
Yes it does support Safari but, it is not much stable as of now!
Prerequisite: Install Safari on Windows
Go to http://docs.seleniumhq.org/download/
Scroll down -> Go to the section "SafariDriver" and download "SafariDriver.safariextz"
Double click on "SafariDriver.safariextz" (previously downloaded)
Safari would open with a pop up containing "Install" button -> Click Install button
Now go to Preferences of Safari and you would see WebDriver (in my case WebDriver 2.48.0) is installed (Enable WebDriver checkbox is checked))
Write the WebDriver Java code as below:
WebDriver driver = new SafariDriver();
driver.get("https://www.packtpub.com/web-development/mastering-selenium-testing-tools-video");
No. It does not support Safari 2 or 3 with the WebDriver according to the compatibility page.

Categories