Reputation: 61
I have capture the current URL on the page. using :
String url = driver.getCurrentUrl();
Now I want a specific text inside this string. Let say
String url = http://www.youtube.com/watch?v=R5-gtsdenpE
and I want
I am using JAVA to write my scripts on Ubuntu.
Upvotes: 0
Views: 132
Reputation: 882
Use:
String fullURL = http://www.youtube.com/watch?v=R5-gtsdenpE;
String emb = fullURL.split("\\?v=")[1];
Upvotes: 1
Reputation: 271
If you are requirement is static and you are sure that you have to get the value after "v" than you can try this also
String emb = url.substring(url.indexOf("v"), url.length()).trim();
Upvotes: 0
Reputation: 1
Url url = new Url(driver.getCurrentUrl());
Map<String, String[]> params = parameterMapFromString(url.getQuery());
String v = params.get("v")[0];
Upvotes: 0
Reputation: 4202
This is what you want I guess-
String string = "http://www.youtube.com/watch?v=R5-gtsdenpE";
URL url = new URL(string);
System.out.println(url.getQuery());
Handle the exception appropriately.
In case you don't want to use URL class, just search for the first index of ? and then use substring() to get the string after that.
System.out.println(string.substring(string.indexOf("?")+1));
Upvotes: 0