0

I am trying to access site with https and SSO enabled. I have passed userid and password in URL itself but that is not working on chrome browser.

I have observed that there is kind of token in the url which is getting added in between url. THis token is new for eveytime you access the url.

What I think will work here is .. access the url -> which will add a new token in url -> authentication popup will come -> i will then get the current url (with current token) -> driver.get this fetched url

I have tried this manually and its working fine..

Can someone please help me in getting the current url value when authentication popup is still open since for me the control is not moving to next line with below code.

    public static void main(String[] args) throws InterruptedException, AWTException {

    WebDriver driver = new ChromeDriver();

    driver.manage().window().maximize();

    driver.get("url_without_token");

    // here authentication will come and url is updated with token

    String currentURL = driver.getCurrentUrl();
    System.out.println(currentURL);
    driver.get(currentURL);
} 
Dolly
  • 97
  • 3
  • 18

2 Answers2

1

You can do something like this:

        wait.until((ExpectedCondition<Boolean>) driver ->
                webDriver.getCurrentUrl().contains("token")
        );

Where "token" is a name of your token parameter from url.

BBB
  • 43
  • 1
  • 9
  • This may not work in case the user does not know what the expected value of the token is. But, if the URL parameter is something like “?token={someValue}” then it will work. Just depends on how the token parameter is named. – CEH Nov 26 '19 at 14:43
  • This will not work as token is not fixed and keeps changing everytime – Dolly Nov 27 '19 at 05:10
  • You can store old token and verify if it's changed – BBB Nov 27 '19 at 10:03
-1

Use the waits like sleep or implicit wait:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Check this answer: Getting the URL of the current page using Selenium WebDriver

  • The issue in this question is about authentication. What does implicit wait have to do with this? – CEH Nov 26 '19 at 14:41