Running IE as a different user with Selenium Webdriver in Java

前端 未结 6 738
灰色年华
灰色年华 2021-01-19 02:55

Does anyone know how I could get selenium to run an IE session utilising the \"Run as different user\" function using JAVA? I have no idea how I\'d even go about setting th

6条回答
  •  悲&欢浪女
    2021-01-19 03:50

    The only solution I got is to use robot class to open new session. Actually IE is not providing any shortcut to open new session so we have to do this by robots.

    This code will open a new session for you. Best of luck

        System.setProperty("webdriver.ie.driver","./IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();
        driver.get("http://www.google.com/");
    
        try{
            Robot robot=new Robot();
            robot.keyPress(KeyEvent.VK_ALT);
            Thread.sleep(3000);
            robot.keyPress(KeyEvent.VK_F);
            robot.keyRelease(KeyEvent.VK_ALT);
            robot.keyRelease(KeyEvent.VK_F);
            robot.keyPress(KeyEvent.VK_I);
            robot.keyRelease(KeyEvent.VK_I);
    
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());
        }
    

提交回复
热议问题