Have selenium interact with safari "store password" popup? - selenium

I have a selenium test that tests the login of a site through a browser instance available on a selenium-grid. This works fine when using a firefox browser instance but when using safari the test cannot get through the entire test because safari pops up a window with the question "Would you like me to save this password".
It doesn't seem to appear as a window_handle nor as an alert. How can I have selenium dismiss this safari popup and continue its test?

You can't. WebDriver cannot interact with browser and/or OS specific dialogs.
You probably have two choices:
Save/dismiss the password manually the first time you run through the test, then reuse the profile every time.
Press Enter or Esc programatically via your programming language. You didn't specify which one you're using, so here's a Java example:
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
It's a hack, but it's reliable and it's what I've been doing to overcome similar issues.

Try this code, it uses JavaScript to change the password to text, and this stops the pop-up:
driver.executeScript("Array.prototype.slice.call(document.getElementsByTagName('input')).forEach(function(e){e.type=e.type=='password'?'text':e.type;});");

Alternatively, you can selectively disable password capture for specific domains. You can also disable password capture altogether by clearing the auto-fill option for username/password.

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.

Selenium test closing window dialog

I'm using Selenium with Robot Framework to write my GUI tests. One of the tests is verifying if, when the user clicks on the Close window/tab button (outside of the webpage), it triggers the alert box before exiting.
I've tried the keywords "Close window" and "Close browser", but both of them ignore the event and close the window. I also tried to close the window with javacript window.close();, but it doesn't work for windows that aren't opened with window.open(); - it is a security measure. I'm using Selenium Grid with different browsers on Linux and Windows, but everytime is failing. Is there a possibility to check this with selenium or I have to use other tools like AutoIT that automate any GUI, not only the browser?
After five days of searching for a solution, I didn't find one that tries to close the page/tab/window and triggers that alert confirmation box.
Instead, I found a workaround that is similar to that and also triggers the necessary alert which is captured by Selenium: click on a link, reopen the same page or go to another one. Like this:
Go To https://stackoverflow.com/
Handle Alert action=DISMISS
I put here action=DISMISS to simply continue with my test on the same page, but if there is need you can change it to something else.

Is the Selenium click() recognized as human or automation?

My scenario which produces the question goes something like below:
I enter a webpage via normal means, next I press on a button, to start a HTML5 application on this webpage, this application is inside an iFrame. On application start I'm being prompted to either turn the sound on or off. At this point there are two possible outcomes:
1. When I answer this prompt manually, new buttons appear in the application window, as expected.
2. When I answer this prompt through automation via Appium, new buttons do not appear.
Now to the question:
To answer the prompt I use the click() method from Selenium. Is it possible that this click() is not considered to be executed by a human and therefore doesn't trigger necessary things? And since I don't have access to the source of the application can I force the Selenium click() to look exactly like a human click?
Here is the code I use to execute the mentioned click:
//Application loading up, hence the sleep
Thread.sleep(5000);
AppiumTestBase.getDriver().switchTo().frame("e_iframe");
Thread.sleep(5000);
WebElement soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
AppiumTestBase.getStandardWaitTime().until(elementToBeClickable(soundOff));
soundOff.click();
The program is able to find and switch in to the iFrame, there are no cross-origin issues either. The AppiumTestBase is just there for initializing the driver, setup capabilities etc. I also tried clicking the element via Actions and JavaScript, but there was no change in behavior.
In C# a workaround I've found to actually take control of the mouse and move it/click with it is to use "Microsoft.VisualStudio.TestTools.UITesting" for the Keyboard/Mouse libraries. From there, you can tell it "Mouse.Click(new Point(X, Y));"and it will move your mouse to that location and click.
Sample Code:
using Microsoft.VisualStudio.TestTools.UITesting;
var soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
Mouse.Click(new Point(soundOff.Bounds.X, soundOff.Bounds.Y));

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

Automation of DOH Robot tests interrumped by Pop-up message

In order to automate DOH tests during our build process, I use Selenium RC to launch different browsers (IE and Firefox) on a server placed on a different domain than the build machine. Each browser is directed to our runTests.html in order to start DOH.
Sometimes, when a test that uses doh.robot starts, the following message is shown:
"DOH has detected that the current web page is attempting to access DOH, but belongs to a different domain than the one you agreed to let DOH automate. If you did not intend to start a new DOH test by visiting this Web page, press Cancel now and leave the Web page"
but since these tests are unattended it just sits there waiting for someone to click OK, and Selenium times out (in IE 8 it seems like the pop-up disappears automatically but the robot does nothing afterward).
As I said, it doesn't always happen. After you click OK on the Pop-up, the message will stop showing, and the message can go away for several sessions, but then it will show again in which seems to be an arbitrary way.
Does anyone knows a way to prevent this pop-up from showing?
This is probably not the correct way to do it, but in util/doh/robot/DOHRobot.java, you may be able to modify the code to not check that or always simulate pressing "OK". I haven't tried it myself, but I may also need to do that for some of our automated testing.
When the DOH robot is initialized, it first tries to click in the upper left corner of the page you are trying to test. If you obscure this div (you can see it with firebug), then the message will pop up. I think the problem is that your page isn't always loading up quick enough.
It is somewhat of a challenge to fix this. I haven't used DOH in awhile, but I don't think there is any way you can use a setTimeout to fix this. (You can try using setTimeout on the doh.run command, but it might be the case that the DOH robot clicks that div before parsing any doh commands.)
Another thing you might be able to do is add a sort of "wait" command to Selenium, or whatever shell command you are using to fire up the system.