How to handle window open prompt(native) in webdriver.io - webdriver-io

I am using webdriver.io framework. At my application, I have a button that opens a Windows Open prompt (Native), and there I need to choose a folder/file and click Open.
Then returning to my application and continue.
Is there a way to move focus on to this window and control it (Select a path and click Open)?
If not- Is there any other solution someone can offer?

The short answer is probably not, you can't control native dialogs from webdriver.
If it's a file input type for which you want to set a file, you might possibly use webdriver to evaluate a piece of javascript to set the HTMLInputElement.files value of the input element.
This works in modern browsers as mentioned in the mozilla docs

Related

Using selenium drivers to Print to PDF

I am struggling with a problem.
I need to download PDF file when the Print dialog appears.
Here is an example of the dialog
I have tried both the chrome and firefox drivers. But unfortunately still cannot get it working.
I have found the following preference for the firefox
fp.setPreference("print.print_to_file", true);
But it seems that it doesn't work.
It doesn't even get applied into the configuration variables set.
Please suggest any way to automate some actions with selenium and then save to PDF file when this print dialog appears.
Firstly, you need to know selenium is a web automation tool. so it can only operate things belongs to browser. Even that, it can't operate all things belongs to browser, like address bar, favior bar, menu bar of browser.
For most case, the print dialog is not belongs to browser, it supplyed by OS or other software installed on OS. so selenium can't operate it is reasonable.
If your script code by java, you can use java.awt.robot to capture the dialog
and click 'print to file'.
If java.awt.robot can worked as your expect, I think you aslo need to set browser options in your script to give a path for browser to save the printed file, just like when you download file, browse will ask you where to save.
if you not to set that options, i guess it will pop-up another dialog to ask you where to save and this dialog is also not belongs to browser.
it's not easy to use java.awt.robot to set the save path.
Because you need to consider the possbility of script run on different OS, use abosulte path is not workable on different OS. Besides if your script run with seleniu grid, it will make you craze. So if testing print to file feature is not important, i recommend you test it manuall.
You can automate Print to PDF using Testmate as below
http://thetestmate.com/save-as-pdf-in-chrome-testmate-selenium/

Selenium select folder windows dialog

]1
There are many examples on what to do with file upload, however I could not find anything in selecting folder. Any ideas how to handle this ?
UPDATE:
I have tried 3 different ways but none worked :
the first is using sendkeys(). This does not work because there is no input field. This dialog opens when you click a button.
The second is using AutoIt, which is used in the uploading files dialog. It causes an error when i use it because I am not uploading a file but just selecting a folder.
the third is robot, where I copy the path I want to the clipboard and try to paste it with robot. It did not work for me.
Update 2:
If you open chrome://extensions/ on chrome browser and tick developer mode you will see a load unpacked extensions buttons. This is the button that when you click you get this windows dialog:
There are different ways by which you can handle File Upload :
Way 1:
WebElement fileInput = driver.findElement(By.name("uploadfile"));
fileInput.sendKeys("C:/path/to/file.jpg");
Way 2:
By using Robot Class API:
driver.findElement(By.By.name("uploadfile")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_KP_DOWN);
r.keyRelease(KeyEvent.VK_KP_DOWN);
r.keyPress(KeyEvent.VK_KP_RIGHT);
r.keyRelease(KeyEvent.VK_KP_RIGHT);
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
Hope it will help you
Selenium support is for Web browser and not for windows dialogs.
the only option for you is to write automation using coded UI or Autoit.
Selenium only works on Web browser, You can use AutoIT but I see you already tried it. In that case I would suggest you to use Sikuli.

How to get Selenium to respond to Chrome's site init popup?

I am trying out Selenium with ChromeDriver to automate some audio/video tests.
But When I fireup the Chrome Browser with my app it asks me the question http:... wants to use your camera and microphone Allow Deny Options I want to click on Allow and proceed with the scripting on the site. But I cannot proceed without selecting Allow. Unfortunately Chrome pops up this question in a sort of Non-DOM format that I am not able to do a driver.findElement the obvious way and respond with a "click" on the "Allow" option. Has anyone of you encountered this situation and what is the best way to deal with this ?
Cheers !
-- Brian
See this answer (print dialog) or this answer ("Run As..." dialog).
Different dialogs, but the reason (in short, WebDriver can't handle these dialogs) and possible solutions are absolutely the same:
The Robot class, it allows you to "press" programatically anything on the keyboard (or clicking blindly) and therefore getting rid of the dialog by, say, pressing Enter or Esc. However, as told above, any advanced interaction is dependant on OS / language / printer.
// press Escape programatically - the print dialog must have focus, obviously
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);
You can, of course, type anything via this class, too.
AutoIt. It's a Windows program useful for handling any system-level automation. Same dependancy as above.
Note that (as far as I know) you can't really check whether the dialog showed up or not, so you won't be able to catch a possible error if it runs on a computer without a camera...
If you're using a ChromeDriver you can get to any 'native' popups using
Alert popup = webDriver.switchTo().alert();
// here you can examine the text within the alert using popup.getText();
popup.accept();

How to force selenium to detect open window?

js gets downloaded to browser cache.
js contains functionA that constructs the url and calls the window.Open to open the url.
i call the functionA to open the window.
selenium doesnt detect the window at all. i did getAllWindowTitles and getAllWindowNames, etc. But do not see window at all.
by the way the reason i had to this is because when i click on button that has an onclick='calltofunction()', the window is not detected either.
it would be better actually if i can force selenium to see the open window after i click the button.
Thanks!
The straight forward answer that I can think of right now is to move on to Selenium 2.31.0, which has an updated support for WebDriver, and can be used in parallel to Selenium.
Then, it is easy to do ALT+TAB (for Windows, or CTRL+TAB for tabs), and WebDriver picks up the new tab/window and reads off of it.

Unable to find popup window

I am having an issue with finding a popup window in some selenium test code. I am looking at the screen on the test runner and there are two IE windows, one of them is the popup and one of them the page which generated the popup. However selecting that window with
SelectWindow("name=SomeName")
fails. Putting a break point in there and running some diagnostics shows that
GetAllWindowNames()
returns only one window. Very odd. I have duplicated the problem in IE, chrome and firefox so I don't think it is browser specific. I am using C# to drive my tests. Any idea how I might solve this issue?
Edit:
I looked a bit more at how this page actually creates its popup by reloading itself with window.open added to its code. It is rather an odd way to open a popup but I don't see any reason why it isn't valid.
Is there title or some other attribute in popup window's source code? You can locate that using any info you find there. Try to record open popup window in Se IDE and click on something in that popup window. Usually this trick works.
IIRC, there are some situations where SElenium fails to register the window. In this case you can register the window anyway by using the openWindow(ยดยด, ). I think this is described in the explanation of openWindow in Selenijum IDE...