In my web appilcation, i need to click on the cancel button of the print preview window of chrome that comes up. I found some code in web to switch between the windows, but for some reason, it doesnt seem to be working. please help.
driver.findElement(By.xpath("//*[#id='PrintBill']")).click();
driver.findElement(By.xpath("//*[#id='savebill']")).click();
// This is in the parent window.
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
driver.findElement(By.xpath("//*[#id='print-header']/div/button[2]")).click();
//this is in the child window(print preview window)
This is where i found the code from... http://seleniumwebdriverfaq.blogspot.in/2012/02/how-can-i-switch-webdriver-control-to_4426.html
It looks like the problem is that Chrome print page is not just another browser window but a modal dialog box which means Selenium probably can not interact with it. So what you can do instead is to use Robots. Here is an example solution for your issue. Go straight down to post #11:
Handling the print dialog box
I quickly checked it on a sample page and it works fine.
Related
When we use JAWs for accessibility purpose we find an issue with Tab button. It's work correct for IE browser, but wrong for Edge. When SWT Edge browser widget display and we use Tab button JAWs pronounce wrong Link/Button label, (it repeat the previous one, but if we click Enter right link will open).The issue is random, sometimes it's work correct but sometimes simply repeat the previous Link title/label. It's work ok if I use U button but wrong for Tab. I've tested browser's part locally running it at Edge browser and found that Tab button work correct with JAWs. But when I run application as a part of Eclipse RCP application with SWT Edge browser I found an error. It seems like we have some conflict/problem between SWT Edge and Jaws. May be some one understand the problem and can help with it? Thank you
I am testing web site functionality with Selenium using Java from Eclipse. One test is to click a "download" button, look for a popup window (this is another selenium window), respond to that window which should then cause a Windows download dialog to pop up (please see attached image).
Please note. I do not have to actually download the file. Just verify that the windows dialog popped up.
I know from experience (or at least am unaware) that Selenium can actually access the Windows download box, choose a file location and start the download. But all I need to do is verify that the download box popped up. Exiting the chromedriver will kill the download window so it won't linger but I still need to verify it was created.
Any suggestions? One thing I tried was having the task manager open. I thought I could find a process corresponding to the dialog box, but there were 119 processes before the dialog box came up as well as when it was up. So any suggestions what to do?
I could add as an aside that someone wrote a workaround to actually download the file. Instead of clicking on a button or link he pretended to be the Windows dialog box and accepted the download. That, for reasons I stated above, will not work in this instance as I have to verify the actual results of clicking the button.
Please see my attached image for an example of the dialog box.
One workaround to meet this test requirement is, once you responds to the window which results in a Windows download dialog, try performing the next action. This will result in a WebDriverException as the access to UI will be blocked by the Windows dialog. You can then catch this WebDriverException and in the catch block press escape key using Robot class in Java. Following is an example:
try {
//1) Respond to the window that results in Windows dialog box.
//2) Perform the next action on UI.
} catch (WebDriverException we) {
//3) You can capture screen shot as well at this stage.
System.out.println("Most likely Windows dialog appeared.");
//4) Press escape key using Robot class in Java
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
}
You can use AutoIT to check if the windows dialog appears, then save the status of the windows dialog in somewhere(eg. a temp file), then you read the status of the windows dialog using Java from Eclipse
I am using Selenium Webdriver with Java. I have an issue: when I click on menu button, the menu control is notfound in safari browser. How do I solve it?
For this problem you have to use short cuts.
For example you need to open FILE menu then you have a short cut "ALT+F"
You can do this with Actions class in Selenium web driver.
Example:
new Actions(driver)
.keyDown(Keys.ALT)
.sendKeys("F")
.keyUp(Keys.ALT)
.perform();
Here I have use ALT + F key to open menu.
Your problem is solve easily by this code.
===============================================================
Note : If there is bug or defect in Safari Menu then This will not work properly. So please check it manually first then apply automation on that.Save time. :)
i'm new to selenium so i don't know weather to ask this question or not please correct me if im wrong ..
i have a site where clicking a button opens the link in a new tab i have succefull used the selenium windowhandle and done the work on the new open tab but when switching to the parent tab i have a problem that is the code is being executed in that parent tab but the tab is not being focused so i can't see how my code is being executed in parent window for that i know to press Crlt +1 using java robot but is there any other way of haveing the focus back to my parent window so that i can see what is happening...
Thanks in Advance
This is what I use:
webDriver.switchTo().window(webDriver.getWindowHandles().toArray()[0])
To bring the window to front of all the windows I think you can try this.
webdriver .manage().window().maximize();
I need to manipulate Popups & Download Dialogs of IE browser using either Java or
Javascript based automated solution.
I tried with selenium2 but its not working properly so any other suggestion for the same.
Actually selenium2 does not provide proper handling of alert/download dialogs so
I am thinking to use some other javascript/java solution.
With Download Dialog: I need to save the downloaded file to particular location.
With Alerts Dialogs: I need to check the displayed message and click on the particular button.
Any suggestion is appreciated.
Thanks.
I use selenium 1 and it works well to handle popups in my application.
//Click on browse file button, open a popup
selenium.click("//input[#value='Browse...']");
//waiting for popup to load
selenium.waitForPopUp("_Dialog", "30000");
//selecting the popup by passing window name
selenium.selectWindow("name=_Dialog");
//click a link inside pop up window
selenium.click("link=something");
//Put other popup operations here
//click cancel button for pop up
selenium.click("cancel");
//back to main window
selenium.selectwindow("null")
To get the message from alert boxes, use selenium.getAlert();. This will return the message contained in the alert box as String.
Also, sometime you will need to check, whether alert has occurred before switching to it.
int noofWindows = selenium.getAllWindowNames().length;
if (noofWindows > 1){
//selects the second window
selenium.selectWindow(selenium.getAllWindowIds()[2]);
//Prints the message in the alert window
System.out.println(selenium.getAlert());
}
If it is not a necessity to run test in IE, use firefox(*chrome) and close all other windows before executing the code.
I hope this helps you.
*All the mentioned code is for handling JavaScript pop-ups. I'm not sure whether this will work for Vb-script or not.
EDIT
I think IE download pop up is a windows event so cannot be handled by selenium directly, for this you'll have to use Java AWT or AutoIT.
AutoIT script should be something similiar to
WinWaitActive(windowTitle)
ControlClick(windowTitle,"",buttonName)
and save it as IEsave.exe. NOTE: I'haven't tried this AutoIT script.
now you have execute IEsave.exe from your program. I'm using java here.
java.lang.Runtime.getRuntime().exec("c:/IEsave.exe");
This will execute the file which in-turn will handle the save button event for windows.
You can create similar exe files for handling other window's events.
Hope this solves your problem.