Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium |将已打开的浏览器(IE)连接到webdriver_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java Selenium |将已打开的浏览器(IE)连接到webdriver

Java Selenium |将已打开的浏览器(IE)连接到webdriver,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在进行一个网站的自动化工作,我需要使用用户a执行一些操作,然后用户B需要批准这些操作 默认情况下,web应用程序从windows登录本身获取凭据,因为此应用程序没有登录页面 所以我所做的是,我自动化了用户A的所有操作。现在,为了从用户B执行操作,我创建了一个.vbs实用程序,我在java代码中调用该实用程序,该实用程序打开一个web浏览器,并使用用户B登录到应用程序中(为此,我在vbs中使用了shell脚本)。现在,我有两个web浏览器,一个是由webdriver打开的(我对用户A执行了一些

我正在进行一个网站的自动化工作,我需要使用用户a执行一些操作,然后用户B需要批准这些操作

默认情况下,web应用程序从windows登录本身获取凭据,因为此应用程序没有登录页面

所以我所做的是,我自动化了用户A的所有操作。现在,为了从用户B执行操作,我创建了一个
.vbs
实用程序,我在java代码中调用该实用程序,该实用程序打开一个web浏览器,并使用用户B登录到应用程序中(为此,我在vbs中使用了shell脚本)。现在,我有两个web浏览器,一个是由webdriver打开的(我对用户A执行了一些操作),另一个是由vbs实用程序打开的(我需要在此浏览器上执行一些操作)由于我的第二个浏览器没有被Webdriver打开,我正在寻找一种方法将其附加到Webdriver,以便我可以对其执行一些操作&批准用户a创建的请求

其他信息: 我需要在IE中执行此操作,因为这是客户的要求。
我正在使用java for selenium。

通过阅读您的问题,我认为您解决问题的方法不正确。由于我无法告诉您在浏览器中处理的是哪种身份验证,因此我想我可以向您展示一个表单和HTTP 401,它很可能涵盖一般情况。如果您需要其他一些示例,以获得不同的身份验证方法,请务必让我们知道

如果我误读了你的请求,而你真的想挂接一个手动启动的浏览器实例(默认情况下不提供),那么你必须真正发挥创造力。不管怎样,这个问题已经得到了回答

然而,就我的建议而言,我强烈建议您尽可能摆脱vb脚本/手动浏览器。如果您可以通过浏览器进行身份验证,那么就可以通过selenium进行身份验证。以下是一些例子:

场景1:使用HTML表单 示例HTML代码:

<form>
    <table id="credentials_table">
    <tbody>
    <tr>
        <td class="credentials_table_label_cell"><label for="username" id="label_input_1">Username</label></td>
        <td class="credentials_table_field_cell"><input class="credentials_input_text" value="" id="username" autocomplete="off" autocapitalize="off" type="text"></td>
    </tr>
    <tr>
        <td class="credentials_table_label_cell"><label for="password" id="label_input_2">Password</label></td>
        <td class="credentials_table_field_cell"><input class="credentials_input_password" value="" id="password" autocomplete="off" autocapitalize="off" type="password"></td>
    </tr>
    <tr id="submit_row">
        <td class="credentials_table_field_cell"><input class="credentials_input_submit" value="Logon" type="submit"></td>
    </tr>
    </tbody></table>
</form>    


你为什么不打开一个新的webdriver,转而创建一个vbs呢?
private WebDriver driverForA = new InternetExplorerDriver();
private WebDriver driverForB = new InternetExplorerDriver();

@After
public void after() {
    driverForA.close();
    driverForB.close();
}

@Test
public void testADoesThisAndBDoesThat() {

    driverForA.get("http://my.login.url");
    final WebElement usernameInput = driverForA.findElement(By.id("username"));
    final WebElement passwordInput = driverForA.findElement(By.id("password"));
    final WebElement submitButton = driverForA.findElement(By.xpath("//input[@type='submit' and @value='Logon']"));
    // perform the login stuff
    clearKeysAndSetValue(usernameInput, "Joe");
    clearKeysAndSetValue(passwordInput, "superSecret");
    submitButton.click();
    // navigate to other pages and do things

    driverForB.get("http://my.approval.page");
    final WebElement approveButton = driverForB.findElement(By.id("approval_Button"));
    approveButton.click();

}

private void clearKeysAndSetValue(final WebElement element, final String valueToSet) {
    element.clear();
    element.sendKeys(valueToSet);
}
private final WebDriver driverForA = new InternetExplorerDriver();
private final WebDriver driverForB = new InternetExplorerDriver();

@After
public void after() {
    driverForA.close();
    driverForB.close();
}

@Test
public void testADoesThisAndBDoesThatHttpBasic() {
    // authenticate as a
    WebDriverWait wait = new WebDriverWait(driverForA, 5);      
    Alert alert = wait.until(ExpectedConditions.alertIsPresent());     
    alert.authenticateUsing(new UserAndPassword("Joe", "superSecret"));
    // navigate to other pages and do things

    driverForB.get("http://my.approval.page");
    final WebElement approveButton = driverForB.findElement(By.id("approval_Button"));
    approveButton.click();
}