Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Selenium在同一个选项卡中打开新的URL,但通过某种方式编辑URL?_Java_Selenium_Url_Intellij Idea_Qa - Fatal编程技术网

Java 如何使用Selenium在同一个选项卡中打开新的URL,但通过某种方式编辑URL?

Java 如何使用Selenium在同一个选项卡中打开新的URL,但通过某种方式编辑URL?,java,selenium,url,intellij-idea,qa,Java,Selenium,Url,Intellij Idea,Qa,我想在Selenium的同一选项卡中打开一个新URL,但我需要以某种方式编辑URL。你能推荐一些工作选择吗?我正在考虑按键导航,但问题是无法检查URL。有一种称为getCurrentUrl的Selenium方法。像这样使用它 String currentURL = driver.getCurrentUrl(); String newURL = currentURL + "yourEdit"; 要在同一选项卡上打开和编辑url,请执行以下操作: 1) 首先,您需要获取当前页面url,为此: ge

我想在Selenium的同一选项卡中打开一个新URL,但我需要以某种方式编辑URL。你能推荐一些工作选择吗?我正在考虑按键导航,但问题是无法检查URL。

有一种称为
getCurrentUrl
的Selenium方法。像这样使用它

String currentURL = driver.getCurrentUrl();
String newURL = currentURL + "yourEdit";

要在同一选项卡上打开和编辑url,请执行以下操作:

1) 首先,您需要获取当前页面url,为此:

getCurrentUrl命令:

用法:用于获取中当前打开的网页的URL 浏览器

语法:driver.getCurrentUrl()

返回类型:字符串(返回当前网页的URL)

示例:

String currentURL  = driver.getCurrentUrl();
System.out.println(currentURL);
2) 现在编辑url: 使用上述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);

这对你有用吗<代码>字符串newURL=https://somedomain.com/path?query=1 获取(newURL)