How to open new URL in the same tab with Selenium, but with some way with editing the URL?
To open and edit the url on the same tab:
1) First you need to get the current page url, to do so:
getCurrentUrl command :
Usage : Used to get the URL of the currently opened web page in the browser.
Syntax : driver.getCurrentUrl();
Return type : String (Returns the URL of current web page)
Example :
String currentURL = driver.getCurrentUrl();System.out.println(currentURL);
2) Now editing url: With the above url, now you can change whatever to want to: example:
String currentURL = driver.getCurrentUrl();//Let assume CurrentUrl = {something}/product/id1/String editURL = currentURL.replace("id1", "id2") ORString editURL = currentURL + "/something/";
3) Opening edited url on the same tab.
driver.get(editURL); ORdriver.navigate().to(editURL);
There is a Selenium method called getCurrentUrl
. Use it like so,
String currentURL = driver.getCurrentUrl();String newURL = currentURL + "yourEdit";