Kalpesh
Kalpesh

Reputation: 23

How to verify the redirection of link in selenium using java

I am clicking on a particular button/link which redirects to another page, I just want to verify that it is redirecting me to the correct page.

I am using Java and onClick().

Upvotes: 1

Views: 5260

Answers (2)

Murthi
Murthi

Reputation: 5347

expectedURL="{expected URL}";
driver.findElement(By.xpath("xpath for the button").click();
String redirectURL=driver.getCurrentUrl();
Assert.assertEquals(redirectURL,expectedURL);

Upvotes: 1

Oleksii
Oleksii

Reputation: 1643

  1. You need to save in variable the link
  2. After redirect you should save in variable browser.getCurrentUrl()
  3. Compare those two variables.

Upvotes: 1

Related Questions