Reputation: 15
I have a URL with some dynamic parts
https://{env}-my-website.{domain}/UnDefault.aspx
And every time I want to go to another module I have to replace this part
UnDefault.aspx
with the module to which I want to navigate e.g.
Modules/Repairs/SNH.aspx
Is there an easy way to do that with Selenium or Regex?
this is what i tried :
String currentUrl = driver.getCurrentUrl();
String[] results = StringUtils.substringsBetween(currentUrl, "https", "?:cn|com");
String SNH= results[0]+"Modules/Repairs/SNH.aspx";
driver.navigate().to(SNH);
Upvotes: 0
Views: 484
Reputation: 425033
To replace the path part of the url (everything after the server):
String url = url.replaceAll("^(.*?//[^/]+/).*", "$1Modules/Repairs/SNH.aspx");
Upvotes: 1