我在不同的机器上使用Selenium来自动测试MVC Web应用程序.
我的问题是我无法获得每台机器的基本URL.
我可以使用以下代码获取当前url:
IWebDriver driver = new FirefoxDriver();
string currentUrl = driver.Url;
Run Code Online (Sandbox Code Playgroud)
但是,当我需要导航到不同的页面时,这无济于事.
理想情况下,我可以使用以下内容导航到不同的页面:
driver.Navigate().GoToUrl(baseUrl+ "/Feedback");
driver.Navigate().GoToUrl(baseUrl+ "/Home");
Run Code Online (Sandbox Code Playgroud)
我使用的可能解决方法是:
string baseUrl = currentUrl.Remove(22); //remove everything from the current url but the base url
driver.Navigate().GoToUrl(baseUrl+ "/Feedback");
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法可以做到这一点?