How to check page url with Selenide

9.2k views Asked by At

How to check page url in selenide ?

For example I should check if url() is www.google.pl

Thanks

2

There are 2 answers

0
gore On

You need to get browser address url. This is how to get current url by Selenide:

String currentUrl = WebDriverRunner.getWebDriver().getCurrentUrl();

Solution example with junit4 assertEquals() method:

String url = "http://www.google.pl";
Selenide.open(url);
String currentUrl = WebDriverRunner.getWebDriver().getCurrentUrl();
assertEquals(url, currentUrl);

with junit4 & Selenide imports:

import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.WebDriverRunner;
import static org.junit.Assert.assertEquals;

Tested. Results: enter image description here

0
Artem Borsuk On

Selenide support checking urls from version 5.23.0. Enjoy

import static com.codeborne.selenide.WebDriverConditions.*;

webdriver().shouldHave(url("https://auth.google.com"));
webdriver().shouldHave(url("https://mastercard.ee"), Duration.ofSeconds(42));
webdriver().shouldNotHave(url("http://yandex.ru");
webdriver().shouldNotHave(urlStartingWith("ftp://"));
webdriver().shouldHave(currentFrameUrl(baseUrl + "/login.html"));
webdriver().shouldHave(currentFrameUrlStartingWith(baseUrl + "/logout.html"));```