1

I have 1 problem. I open a page (referred to as tab 1) and then click the Facebook button on that page. Screen redirect to the Facebook sign-in page (known as tab 2). I tried using the get url of tab 2 function, but it only returned the url for tab 1. I do not believe that I am switching to tab 2. then, how do you fix it? I greatly appreciate it.

I want to get url of tab2

  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jul 13 '23 at 15:55

1 Answers1

0

You need to switch to new window then try to get the URL.

    String parentWindow = driver.getWindowHandle();
    Set<String> windows = driver.getWindowHandles();
    for(String eachwindow: windows)
    {
        if(!eachwindow.equals(parentWindow))
        {
            driver.switchTo().window(eachwindow);
        }
    }
    
    String url = driver.getCurrentUrl();
    System.out.println(url);
Ketan Pardeshi
  • 516
  • 1
  • 5
  • 8