我想在 Selenium 的同一个选项卡中打开一个新的 URL,但我需要以某种方式编辑该 URL。有哪些工作选择?我正在考虑按键导航,但问题是无法检查 URL。
最佳答案
要在同一个选项卡上打开和编辑 url:
1) 首先您需要获取当前页面的 url,为此:
getCurrentUrl 命令:
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)
示例:
String currentURL = driver.getCurrentUrl();
System.out.println(currentURL);
2) 现在编辑网址: 使用上面的 url,现在你可以更改任何想要的: 示例:
String currentURL = driver.getCurrentUrl();
//Let assume CurrentUrl = {something}/product/id1/
String editURL = currentURL.replace("id1", "id2")
OR
String editURL = currentURL + "/something/";
3) 在同一选项卡上打开已编辑的 url。
driver.get(editURL);
OR
driver.navigate().to(editURL);
关于java - 如何在与 Selenium 相同的选项卡中打开新 URL,但以某种方式编辑 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55163306/