robot.keyPress(KeyEvent.VK_TAB);在警报中不起作用

时间:2016-12-07 11:16:45

标签: selenium-webdriver

我必须自动化身份验证窗口,因为我使用Mac我无法使用AutoIT因此我尝试使用此代码

driver.get("https://mainsite.com"); //main(parent site)

Alert alert = driver.switchTo().alert(); //shifts focus to authentication window

    alert.sendKeys("username"); //fills username in authentication window
    try {

    Robot robot = new Robot();      
    robot.keyPress(KeyEvent.VK_TAB);        
    robot.keyRelease(KeyEvent.VK_TAB);
    } catch (AWTException e) {
    e.printStackTrace();
    }

alert.sendKeys("password"); 

alert.accept();

当我执行此代码时,用户名将被填入警报,但robot.keyPress(KeyEvent.VK_TAB);不起作用,密码将填入相同的用户名字段,因此不接受警报。

screenshot

0 个答案:

没有答案