Selenium is a web testing framework that allows you to automate browser interactions. One way to use Selenium is to verify the current URL of a webpage. This can be done using the .current_url property of the webdriver object.
driver.getCurrentUrl();
We can take the current URL and verify it with the URL we passed.
String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "http://localhost:8080/imdb/homepage" );
This is how it looks when we want to assert a URL using assertEquals.
WebDriverManager.chromedriver().setup();
ChromeDriver driver = new ChromeDriver();
driver.get("http://autopract.com/selenium/alert5/");
driver.manage().window().maximize();
String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "http://autopract.com/selenium/alert5/");
This will get the current URL it is in and asserts with the URL we provide to match it.
- Log in to post comments