如何在C#中使用Selenium WebDriver获取当前窗口的URL? [英] How to get the URL of the current window using Selenium WebDriver in C#?
问题描述
在我的应用程序中登录时,然后导航到另一个页面.现在,我需要在Selenium C#中使用WebDriver获取该新URL.
In my application when sign-in, then it navigates to another page. Now I need to get that new URL using WebDriver in selenium C#.
我找不到任何执行此操作的功能.我尝试了driver.Url
,
driver.getLocation()
和driver.getCurrentUrl()
,但是在我的C#应用程序中没有任何工作.那么是否有可能以某种方式获取当前URL?在导航之后?
I can't find any function to do this. I have tried driver.Url
,
driver.getLocation()
and driver.getCurrentUrl()
, but nothing is working in my C# application. So is it possible get the current URL somehow? After it gets navigated?
推荐答案
是的,您可以获得当前页面的URL.实例化您的驱动程序,然后获取驱动程序的 Url 属性.
Yes, you can get the URL of the current page. Instantiate your driver and then get the driver's Url property.
代码段:
IWebDriver driver = new FirefoxDriver();
String currentURL = driver.Url;
帮助: 硒:找到基本网址
这篇关于如何在C#中使用Selenium WebDriver获取当前窗口的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!