java - Selenium | Attach already opened browser(IE) to webdriver -


i working on automation of website in need perform action using user a user b needs approve same.

by default web-application takes credentials windows login there no login page this.

so did was, automated actions user a. perform action user b ,i created .vbs utility calling in java code, utility opens web browser , sign application user b (i used shell scripting in vbs this). have 2 web browser 1 opened webdriver (on performed action user a) , other has been opened vbs utility(i need perform action on browser) , since second browser not opened webdriver searching way attach webdriver can perform actions on & approve request created user a.

additional information: need perform in ie since client requirement. using java selenium.

from reading question, believe tackling problem incorrectly. since cannot tell sort of authentication dealing in browser, suppose can show form , http 401, cover general scenarios. if need other example, different way authenticate, let know.

if have misread request, , want hook onto manually started instance of browser, not provided default, have creative. regardless, question answered here.

however, far recommendation goes, highly recommend rid of vb script / manual browser starting if possible. if can authenticate through browser, can through selenium. here examples:

note, guide on how use internetexplorerdriver

scenario 1: using html form sample html code:

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

sample selenim code login:

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' , @value='logon']"));     // perform login stuff     clearkeysandsetvalue(usernameinput, "joe");     clearkeysandsetvalue(passwordinput, "supersecret");     submitbutton.click();     // navigate other pages , 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); } 

scenario 2: using http 401

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     webdriverwait wait = new webdriverwait(driverfora, 5);           alert alert = wait.until(expectedconditions.alertispresent());          alert.authenticateusing(new userandpassword("joe", "supersecret"));     // navigate other pages , things      driverforb.get("http://my.approval.page");     final webelement approvebutton = driverforb.findelement(by.id("approval_button"));     approvebutton.click(); } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -