Accept permission request in chrome using selenium

后端 未结 8 1794
旧巷少年郎
旧巷少年郎 2020-12-10 06:37

I have a HTML/Javascript file with google\'s web speech api and I\'m doing testing using selenium, however everytime I enter the site the browser requests permission to use

相关标签:
8条回答
  • 2020-12-10 07:09

    @ExperimentsWithCode

    Thank you for your answer again, I have spent almost the whole day today trying to figure out how to do this and I've also tried your suggestion where you add that flag --disable-user-media-security to chrome, unfortunately it didn't work for me.

    However I thought of a really simple solution:

    To automatically click on Allow all I have to do is press TAB key three times and then press enter. And so I have written the program to do that automatically and it WORKS !!!

    The first TAB pressed when my html page opens directs me to my input box, the second to the address bar and the third on the ALLOW button, then the Enter button is pressed.

    The python program uses selenium as well as PyWin32 bindings.


    Thank you for taking your time and trying to help me it is much appreciated.

    0 讨论(0)
  • 2020-12-10 07:09

    Building on the answer from @Shady Programmer.

    I tried to send Tab keys with selenium in order to focus on the popup, but as reported by others it didn't work in Linux. Therefore, instead of using selenium keys, I use xdotool command from python :

    def send_key(winid, key):
        xdotool_args = ['xdotool', 'windowactivate', '--sync', winid, 'key', key]
        subprocess.check_output(xdotool_args)
    

    which for Firefox, gives the following approximate sequence :

    # Focusing on permissions popup icon
    for i in range(6):
        time.sleep(0.1)
        send_key(win_info['winid'], 'Tab')
    
    # Enter permissions popup
    time.sleep(0.1)
    send_key(win_info['winid'], 'space')
    
    # Focus on "accept" button
    for i in range(3):
        time.sleep(0.1)
        send_key(win_info['winid'], 'Tab')
    
    # Press "accept"            
    send_key(win_info['winid'], 'a')
    
    0 讨论(0)
提交回复
热议问题