用于检查 selenium webdriver 中的 url 的断言命令
Assert command for checking the url in selenium webdriver
由于网页上没有 url 的 xpath 和 id,我如何检查我的实际 url 是否与预期的 url 匹配?
我在下面提供了我的代码,但没有用。
String Actualtext = driver.findElement(By.linkText("http://localhost:8080/imdb/homepage")).getText();
Assert.assertEquals(Actualtext, "http://localhost:8080/imdb/homepage" );
System.out.println("URL matching --> Part executed");
getText()
用于获取可见的 innerText,您可以使用 getAttribute
方法获取 url (用于超链接),如下所示
String Actualtext = driver.findElement("YourElementLocator").getAttribute("href")
Assert.assertEquals(Actualtext, "http://localhost:8080/imdb/homepage" );
System.out.println("URL matching --> Part executed");
您可以根据 'current url' 作为
验证它
String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "http://localhost:8080/imdb/homepage" );
在Python中,不是getCurrentUrl
,而是
driver.current_url
在 selenium webdriver C#中
字符串URL = driver.Url;
Assert.AreEqual(URL, "http://localhost:8080/imdb/homepage");
在 Selenium 网络驱动程序中 java
字符串URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "http://localhost:8080/imdb/homepage" );
由于网页上没有 url 的 xpath 和 id,我如何检查我的实际 url 是否与预期的 url 匹配?
我在下面提供了我的代码,但没有用。
String Actualtext = driver.findElement(By.linkText("http://localhost:8080/imdb/homepage")).getText();
Assert.assertEquals(Actualtext, "http://localhost:8080/imdb/homepage" );
System.out.println("URL matching --> Part executed");
getText()
用于获取可见的 innerText,您可以使用 getAttribute
方法获取 url (用于超链接),如下所示
String Actualtext = driver.findElement("YourElementLocator").getAttribute("href")
Assert.assertEquals(Actualtext, "http://localhost:8080/imdb/homepage" );
System.out.println("URL matching --> Part executed");
您可以根据 'current url' 作为
验证它String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "http://localhost:8080/imdb/homepage" );
在Python中,不是getCurrentUrl
,而是
driver.current_url
在 selenium webdriver C#中
字符串URL = driver.Url; Assert.AreEqual(URL, "http://localhost:8080/imdb/homepage");
在 Selenium 网络驱动程序中 java
字符串URL = driver.getCurrentUrl(); Assert.assertEquals(URL, "http://localhost:8080/imdb/homepage" );