How to handle browser authentication in Selenium Webdriver using Java?.


 import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
  public class AuthinticationRequired {   
   public static void main(String[] a) {   
   // Initialize driver   
    WebDriver driver = new FirefoxDriver();   
   //Maximize browser window    
   driver.manage().window().maximize();   
  //driver.get("http://Username:Password@domain_name");   
     //Go to URL   
    driver.get("http://dipil:bangla@localhost:4040");   
  //Set selenium webdriver get timeout   
  driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);     
    // Browser close    
    driver.close();   
   }   
  }   

3 comments:

  1. this logic is not working for me

    ReplyDelete
    Replies
    1. Hi Ravi Teja,
      It's depend on which type of authentication use for server and same code don't work for different authentication. It nice work for me.

      Delete
  2. This Syntax :
    driver.get("http://Username:Password@domain_name");
    wouldn't work if the Password Consists @ symbol.

    For Ex :
    driver.get("http://dipil:ban@1gla@localhost:4040");
    The URL is considered from the first @ symbol. and throws an error.

    Could you suggest a solution for this??

    ReplyDelete