Assert command to check url in selenium webdriver

Since there is no xpath and id for the URL on the webpage, how can I check if my actual URL matches the expected URL?

I provided my code below, but that did not work.

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");
+4
source share
2 answers

You can check it at "current url" as

String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "http://localhost:8080/imdb/homepage" );
+10
source

getText()used to retrieve visible innertText, you can use the method getAttributeto get the url (for hyperlink), something like below

String Actualtext = driver.findElement("YourElementLocator").getAttribute("href")
Assert.assertEquals(Actualtext, "http://localhost:8080/imdb/homepage" );
System.out.println("URL matching --> Part executed");
+1
source

Source: https://habr.com/ru/post/1569958/


All Articles