How to handle authentication popup with Selenium WebDriver using Java

前端 未结 7 1757
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 05:36

I\'m trying to handle authentication popup using the code below:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(\"network.http.phishy-u         


        
相关标签:
7条回答
  • 2020-11-22 06:17

    Popular solution is to append username and password in URL, like, http://username:password@website.com. However, if your username or password contains special character, then it may fail. So when you create the URL, make sure you encode those special characters.

    String username = URLEncoder.encode(user, StandardCharsets.UTF_8.toString());
    String password = URLEncoder.encode(pass, StandardCharsets.UTF_8.toString());
    String url = “http://“ + username + “:” + password + “@website.com”;
    driver.get(url);
    
    0 讨论(0)
提交回复
热议问题