Why doesn't Robot dismiss the Firefox print modal? [Automated testing] - selenium

When opening the print page in Firefox a print dialog is triggered. As is mentioned in the answer linked here (How to handle print dialog in Selenium?), Selenium's WebDriver cant handle these sorts of browser (or OS) dialogs.
Im using Selenium with Java to test a particular website. So I included the following code (as was suggested by the answer linked above) which employed the use of Java Robot to get rid of the print dialog.:
// press Escape programatically - the print dialog must have focus, obviously.
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);
This answer made sense to me because when I manually pressed the escape key, the print dialog was dismissed.
Unfortunately, the code mentioned above did not work for me i.e. the print dialog remained there. As suggested by some other posts, I made sure to wait until the print dialog appeared.
While running the automated test code I'm not entirely sure whether "the print dialog was focused" (as is mentioned in the comment in the code given above). I tried multiple methods to get it "in focus" such as switching to the last web handle, switching to the browser alert etc and all of those threw errors. This further confirmed to me the idea that selenium was unable to handle this dialog. I do suspect that the lack of "focus" on the print dialog is where I'm running into the issue.
I want to be able to dismiss this modal because I open the print page multiple times during my testing run which means that multiple print dialogs open. Once the testing code is completed, the browser quits and only one of these dialogs is closed. Could you please help me figure out what I'm doing wrong?
Im using the following:
Geckodriver version: geckodriver-v0.26.0-macos
Java: 1.8.0_191
MacOS: Version 10.15.5 (19F101)
Firefox version: 78.0.2
Please do let me know what other information I could include to help you answer this. Thanks! I would have commented on the thread I mentioned, but Im new to StackOverflow and you need 50 reputation points to make a comment :(

Related

How to handle Micro Popup in Webdriver.io browser

When starting a website, I find it difficult to click Block button on Microphone popup because I can't query this popup (and also with block btn)
How can I handle this problem with Webdriver.io in browser?
enter image description here
One option is to use chrome command line switches. You can find the list here.
The one you are looking for is use-fake-device-for-media-stream. You can set this in your config file so that every time the chrome is launched, it won't show this popup since it is already set to a fake device.

Move target out of bounds exception

I am writing tests for a web application and all went well until I had to choose an option from a menu and that option displays a drop down list when hovered or clicked. When I click an option from the drop down list, I get the following error:
MoveTargetOutOfBoundsException: Element cannot be scrolled into view
Does anyone know what this error is about and what I should look for in my code?
Selenium version 2.25.0, java version 1.6.0_31
I've been checking some selenium and google groups regarding this issue in older versions https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/EuZ7a6_lB9Q
http://code.google.com/p/selenium/issues/detail?id=3075
http://code.google.com/p/selenium/issues/detail?id=4102
a more recent discussion
Is it a known issue for Selenium 2.25.0 or is there a way to fix it? I recently upgraded to Firefox 15.0 :|
Note: I found a temporary solution until someone magically fixes this...since I can't find where the problem is...
I run the code before that point where it crashes, I put it to sleep for 10 seconds, I manually click the menu and the option from the drop down list, the window I want is displayed and the code continues with actions from that point. It works for now...I hope this will be fixed since I can't believe that I can run a script in Selenium IDE but I can't run my java code in WebDriver ...this is crazy :|
I guess you are trying to click an element from a dropdown.
You should keep in mind, that Selenium helps you replicate exact human behavior. So if the code fails because the element is not visible, it is probably because the element is not visible.
To make it work, you might want to put a click command on the menu before the failing bit of code.
(to replicate the sleep 10 seconds manually click the menu button method you are using)
Once again, if you can show us your code and also the HTML snippet of the Menu section, we can provide an exact solution.
Maybe you're opening new popup window while opening select box.
This may help you:
WebDriver.FindElement(By.Id("someInputBox")).SendKeys("hello");
(IJavaScriptExecutor)WebDriver).ExecuteScript("document.getElementById('windowOpener_Button').click();");
WebDriver.SwitchTo().Window("newDisplayedWindowPopupName"); // continue to test

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();

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...

Selenium RC - selenium-browserbot.js error

I'm writing some automated tests in C# and a JavaScript error is thrown when I try to click on a button that will submit changes made to a web form. The error I am recieving is:
An error has occured in the script on this page
Line: 2004
Char: 9
Error: Permission denied
Code: 0
URL: file:///C:/DOCUME~1/nkinney/LOCALS~1/Temp/customProfileDir6c0c7d7226cc463fb­b1a7f6253c4df62/core/scripts/selenium-browserbot.js
Once the test is finished, the error will still be displayed if I manually click on the button while selenium is running.
The line in selenium to select this button is:
selenium.Click("//input[contains(#id, 'SubmitBtn')]");
I've also tried submit.
A pop-up should be displayed asking the user to confirm they want to make the changes. This error is thrown before the pop-up is displayed and after Selenium 'clicks' on the button.
Any advise would be greatly appreciated.
After further investigation, I found that Selenium is unable to work with custom modal dialog boxes. That said, I don't think I will be able to use Selenium to automate UI testing in our current release. Thanks to anyone who looked at this post.
From the Selenium FAQ
I can't interact with a popup dialog. My test stops in its tracks!
You can, but only if the dialog is an alert or confirmation dialog.
Other special dialogs can't be dismissed by javascript, and thus
currently cannot be interacted with. These include the "Save File",
"Remember this Password" (Firefox), and modal (IE) dialogs. When they
appear, Selenium can only wring its hands in despair.
To solve this issue, you may use a workaround (if one exists);
otherwise you may have to exclude the test from your automated corpus.
For the "Save File" dialog in Firefox, a custom template may be
specified when running via the RC that will always cause the file to
be downloaded to a specified location, without querying the user (see
http://forums.openqa.org/thread.jspa?messageID=31350). The "Remember
this Password" dialog should not appear again after you've chosen to
remember it. Currently there is not much that can be done about IE
modal dialogs.
Do you have the option of seeing if the test runs in another browser (Firefox, Chrome)?
A very similar answer is also here: How do I test modal dialogs with Selenium?