Accept permission request in chrome using selenium

后端 未结 8 1802
旧巷少年郎
旧巷少年郎 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

    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')
    

提交回复
热议问题