我们应该阻止对包含嵌入式凭据(例如“ http://ima_user:hunter2@example.com/yay.tiff ”)的子资源的请求。这些资源将作为网络错误处理。
但是, 功能仍可通过 Selenium-Java 绑定与 Selenium 3.4.0 , geckodriver v0.18.0 , chromedriver v2.31.488763 , Google Chrome 60.x 和 Mozilla Firefox 53.0一起 使用。 __
这是示例代码,它尝试使用一组有效的凭据打开URL ,并且可以正常工作。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class BasicAuthentication_FF
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://admin:admin@the-internet.herokuapp.com/basic_auth");
}
}
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class BasicAuthentication_Chrome
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.navigate().to("http://admin:admin@the-internet.herokuapp.com/basic_auth");
}
}