我正在尝试访问启用了 https 和 SSO 的网站。 我已经在 URL 本身中传递了用户 ID 和密码,但这在 Chrome 浏览器上不起作用。
我观察到 url 中存在某种标记,该标记被添加到 url 之间。每次您访问该网址时,该 token 都是新的。
我认为在这里起作用的是..访问url -> 这将在url中添加一个新的 token -> 身份验证弹出窗口将会出现 -> 然后我将获取当前的url(带有当前 token ) -> driver.get此获取的网址
我已经手动尝试过,它工作正常..
当身份验证弹出窗口仍然打开时,有人可以帮助我获取当前的 url 值吗,因为对我来说,控件不会使用下面的代码移动到下一行。
public static void main(String[] args) throws InterruptedException, AWTException {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("url_without_token");
// here authentication will come and url is updated with token
String currentURL = driver.getCurrentUrl();
System.out.println(currentURL);
driver.get(currentURL);
}
最佳答案
你可以这样做:
wait.until((ExpectedCondition<Boolean>) driver ->
webDriver.getCurrentUrl().contains("token")
);
其中“token”是网址中 token 参数的名称。
关于java - 如何在 selenium 中处理 chrome 中的身份验证弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59044855/