在selenium中动态提取URL的一部分?

时间:2018-06-09 04:38:33

标签: java selenium

使用selenium自动化,我无法动态提取URL。如何使用Java在selenium自动化中动态提取URL的一部分?

1 个答案:

答案 0 :(得分:0)

使用此:

String currentUrl = driver.getCurrentUrl();

您将获得包含当前网址的字符串。例如:https://stackoverflow.com/。假设您要提取此stackoverflow的一部分。然后你可以使用这个示例代码:

String s = "https://stackoverflow.com/";
String output = s.substring(8, 21); // 8 - begin index, 21 - end index
System.out.println(output); // prints 'stackoverflow'