使用selenium自动化,我无法动态提取URL。如何使用Java在selenium自动化中动态提取URL的一部分?
答案 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'