有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用selenium headless模式验证htaccess提示符?

我正试图在eclipse中创建一个JavaSelenium脚本,并在headless模式下运行它。我无法使用head或headless模式对其进行身份验证,但其目的是在headless模式下执行,以便我可以进行回归测试。 脚本基本上打开了URL,出现了一个htaccess提示,请求用户名和密码,我需要输入用户名和密码,然后单击ok,但它不起作用。 下图显示了身份验证提示,我需要在其中输入凭据

enter image description here

下面是代码,我已经尝试过了,但它不起作用

import java.awt.AWTException;
import java.awt.Robot;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class localhost {

public static void main(String[] args) throws InterruptedException, AWTException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","F:\\Rafiq\\Work\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
WebDriver driver =new ChromeDriver(options);

String url = "http://admin:" + "admin_pass" + "@localhost";
driver.get(url);

System.out.println("Title of the page is -> " + driver.getTitle());
driver.close();


//

}
}

共 (0) 个答案