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.
Related
I have done a fair amount of googling and Selenium does not seem to natively support the clicking of the Save button in pop-up box. However I see a workaround which sets the browser preferences in this question -- Access to file download dialog in Firefox
The code given there is as below --
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir","c:\\downloads");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
WebDriver driver = new FirefoxDriver(firefoxProfile);//new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.navigate().to("http://www.myfile.com/hey.csv");
Unfortunately, I cannot navigate to the file location, shown in the line below, since it redirects me to the login page of the website.
driver.navigate().to("http://www.myfile.com/hey.csv")
I have already logged-in to the website and log-in again does not make sense. Even for that I have to open a new window handler and switch to the new window(I don't think it will work anyway, since after login it directs to the previous page from which the pop-up occurs ). Is there some workaround to avoid this
driver.navigate().to
and somehow click on the Save button on the pop-up dialogue box?
Note1: When I manually open my browser, The pop-up window does not appear at all. The file starts to download when I click on the previous link even when I don't change firefox preferences manually to automatically download the file.
Note2: I Changed the Firefox preferences manually to automatically download the file types (XML in my case), but Selenium does not pick up this preference(expected behavior, I guess).
Simply put, it's not possible to interact with anything that's not part of the DOM. You can't make Selenium click on the "Save" button of the browser.
Most of the time it's not a good idea to download a file anyway (at least not when you're just doing UI testing).
Depending on what exactly you want to do with the file I'd suggest finding another way to test that behavior.
I'm Trying to save a Html Page using Selenium script in java which perform following operations
open the web page.
fire a right click event.
click on save as html option.
Now problem is when script click on save as html option it shows a pop-up to save html.
I already set default option for download in Firefox but when i run the script it keep showing me pop-up again and again what i need is:-
when Firefox shows a save as dialog box then it'll fire an enter event so that it can save html by using Selenium script.
Robot class in java might help you. Check this link as well.
Here is a sample code:
// Create object of Robot class<br>
Robot object=new Robot();
// Press Enter<br>
object.keyPress(KeyEvent.VK_ENTER);
// Release Enter<br>
object.keyRelease(KeyEvent.VK_ENTER);
Window pop ups cant be handled by Selenium.So you can go for follwing options : -
(1) Java Robot Class
(2) Sikuli [Recommended]
(3) AutoIt
These are 3rd party tools used to handle window based pop ups.
Accepting confirmation popups in Selenium can be handled via Alert object (assuming driver instance is ready):
Alert myAlert = driver.switchTo().alert();
myAlert.accept();
Use autoit
download the autoit exe
record clicking of that button
Use the code and execute it via JS executor
Dont forget to place the code before you are actually executing the step
not after executing it
Please switch to windows dialogs first using get window handles eg. Save As
Then, use Robot commands to send Enter key.
It will save the file.
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().
We have an Oracle Forms 11g application which can be started via browser.
This leaves an empty browser window, since Forms opens its own window. However, if you close the empty browser window, the Forms window also get closed.
I like the fact that this kind of installation is a server installation and I can easily update it.
But I would prefer an icon (a shourtcut) on the desktop which just opens the Forms application without the browser window. I hoped to resolve this with the AppletViewer from the Java SDK.
However, when I start it with the URL of the start page I receive:
Warning: <embed> tag requires code attribute.
Exception in thread "main" java.lang.NullPointerException
at sun.applet.AppletViewer.parse(AppletViewer.java:1129)
at sun.applet.AppletViewer.parse(AppletViewer.java:1074)
at sun.applet.Main.run(Main.java:156)
at sun.applet.Main.main(Main.java:98)
Does anyone know how I can open the Forms application directly without the browser (and without a local installation of an app)?
PS: I know Run Oracle Forms as standalone without browser, but it didn't help me, because the referenced link isn't online anymore.
Update 1: the link has been replaced, so this might be a solution I will try.
Update 2: we managed to run our Forms apps via Webstart like any other desktop application. Hurrah!
You can have the the Forms app open in the same browser window it was launched from, just put this in formsweb.cfg:
separateFrame=false
You can checkout the solution using Javascript from this Blog post
enter code hereBrief : I am currently using selenium 2.0 to automate the testing of an UI.Everything was fine till yesterday till i came across pop ups.I am having to handle windows popups.
The problem :
I am navigating to page using the following code =>
driver.get("http://xxx.xx.x.xxx:zzzz/yyyy/");
driver.findElement(By.name("username")).sendKeys("username");
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.className("rowClass")).submit();
driver.findElement(By.name("uploadfile")).click(); //this is the browse button
Now the problem arises when i click the browse button.It opens up another windows browse file window.What i need to do is to select a file by navigating to the given path and then select a particular file and i am not able to do the same currently.What could be the suggestion.Some one said it was not possible to do the same using selenium 2.0 and to use autoit instead.if someone knows how to do it please let me know else please suggest a better way to get it done.Thanks and regards.
PS :
//this is mentioned as the solution in http://seleniumhq.org/docs/03_webdriver.htmlbut did not work in my case
Alert alert = driver.switchTo().alert();
This is more of a "How to upload a file in WebDriver?" question which has been asked many times :).
Selenium 2 (WebDriver) Java example:
// assuming driver is a healthy WebDriver instance
WebElement fileInput = driver.findElement(By.name("uploadfile"));
fileInput.sendKeys("C:/path/to/file.jpg");
The idea is to directly send the absolute path of the file to an element which you would usually click at to get the modal window - that is <input type='file' /> element (or the Browse button as you call it).
Also, the Alert interface is just for popup JavaScript dialogs - alert, confirm, prompt.