3

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

Brian Antao
  • 131
  • 2
  • 11

2 Answers2

1

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

Community
  • 1
  • 1
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • The problem with this is that the popup dialog is not in focus and what is typed in via the Robot goes into the WebElement dialog box which comes into focus from the web page. – Brian Antao Jul 20 '12 at 14:05
  • @BrianAntao Ohhh. That's a pickle. You could Alt+Tab to it or click the center of the screen. Yes, both solutions are very unreliable =/. Try it if it works every time. If not, AutoIt should allow you to control the right window, so in this case, it might be the best choice. – Petr Janeček Jul 20 '12 at 14:34
  • Alas does not work ! and AutoIt is not an option for me as I need a solution that will run on Linux ! There has got to be a way to get a handle to this dialog ?? – Brian Antao Jul 20 '12 at 15:31
  • @BrianAntao Unfortunately, I'm not aware of any. The virtual keyboard is your best bet. – Petr Janeček Jul 21 '12 at 09:30
1

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();
cyber-monk
  • 5,470
  • 6
  • 33
  • 42