由于该网页上的网址没有xpath和ID,我如何检查我的实际网址是否与预期的网址匹配?
我在下面提供了我的代码,但是没有用。
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");
您可以使用'当前网址'对它进行验证,以
String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "http://localhost:8080/imdb/homepage" );
getText()
用于获取可见的innertText,您可以使用getAttribute
方法来获取url(对于超链接),如下所示
String Actualtext = driver.findElement("YourElementLocator").getAttribute("href")
Assert.assertEquals(Actualtext, "http://localhost:8080/imdb/homepage" );
System.out.println("URL matching --> Part executed");
在Python中,它不是getCurrentUrl
,而是
driver.current_url