0

I need help with extracting parameter from URL. I have used

String url = driver.getCurrentUrl()

to catch current URL.

After that, I need to extract value from the parameter called oauth_verifier from

http://localhost:4200/consent?oauth_token=something&oauth_verifier=something

so I can use it later in code.

Any help would be great. Thanks in advance!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

Try This One , I Am not Sure Its Right Way , But Its Work...

String str = "http://localhost:4200/consent?oauth_token=something&oauth_verifier=something"; 
        String[] arrOfStr = str.split("/"); 
String temp=arrOfStr[3];
String temp2[]=temp.split("\\?|\\=");
AMAR MAGAR
  • 137
  • 2
  • 13
0

To extract the value associated with oauth_verifier you need to induce WebDriverWait with ExpectedConditions as urlContains() the text oauth_verifier and you can use the following solution:

  • Code Block:

    new WebDriverWait(driver, 20).until(ExpectedConditions.urlContains("oauth_verifier"));
    String fullUrl = driver.getCurrentUrl();
    String[] UrlParts = fullUrl.split("=");
    System.out.println(UrlParts[2]);
    
  • Console Output:

    something
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Assuming its Java ,you should use the substring function of String .

yourstring.substring(indexOf1stCharacter,indexOfLastCharacter)

For your case:

url.substring(url.indexOf("oauth_verifier=") + 15 , url.length());
devx
  • 81
  • 1
  • 4