Accept permission request in chrome using selenium

后端 未结 8 1827
旧巷少年郎
旧巷少年郎 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 06:53

    Beware of Mohana Latha's answer for JAVA! The code is only pressing the buttons and NEVER releasing them. This will bring bunch of issues later on.

    Use this instead:

        // opening new window
        Robot robot;
        try {
            robot = new Robot();
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.delay(100);
            robot.keyPress(KeyEvent.VK_N);
            robot.delay(100);
            robot.keyRelease(KeyEvent.VK_N);
            robot.delay(100);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.delay(100);
        } catch (AWTException e) {
            log.error("Failed to press buttons: " + e.getMessage());
        }
    

提交回复
热议问题