Java 如何使用 selenium Web 驱动程序切换到重定向的 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19755839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 19:56:45  来源:igfitidea点击:

How do I switch to redirected url using selenium web driver

javafacebookseleniumwebselenium-webdriver

提问by user2753523

I would like to know if it is possible to switch to redirected url using java selenium web driver.

我想知道是否可以使用 java selenium web 驱动程序切换到重定向的 url。

I am doing automation for an app in facebook, but the developer of that app has used "Request dialog" facebook api feature which accepts "redirect_url" in java script.

我正在为 facebook 中的应用程序做自动化,但该应用程序的开发人员使用了“请求对话框”facebook api 功能,该功能在 java 脚本中接受“redirect_url”。

How do I switch my web driver to that redirected page?

如何将我的网络驱动程序切换到该重定向页面?

One solution for this is

对此的一种解决方案是

String redirected_url = driver.getCurrentUrl();//This url is not matching with the one  showing in address bar.
driver.get(redirected_url);

Problem with the above is same page is loading again but now with redirected url showing in address bar and it is allowing me to do automation further

上面的问题是同一页面再次加载,但现在地址栏中显示重定向的 url,它允许我进一步进行自动化

I need a solution something like which will use driver.switchTo().

我需要一个类似的解决方案,它将使用 driver.switchTo()。

Actually when I click on a button it is redirecting to another page (redirecting url is internal, we cant see this url in address bar but can fetch using driver.getCurrentUrl()). This redirecting url we can get using selenium web driver but there is no change in page source after redirect

实际上,当我单击一个按钮时,它会重定向到另一个页面(重定向 url 是内部的,我们无法在地址栏中看到此 url,但可以使用 driver.getCurrentUrl() 获取)。我们可以使用 selenium web 驱动程序获得这个重定向 url,但重定向后页面源代码没有变化

Thanks in advance for your help.

在此先感谢您的帮助。

回答by Petr Mensik

I am not familiar with Facebook API but I guess driver.navigate().to(url);is what you are looking for.

我不熟悉 Facebook API,但我想driver.navigate().to(url);这就是您正在寻找的。