How to Wait for a Redirect Chain to Settle using Selenium WebDriver where final page loaded is not predictable?

后端 未结 1 630
谎友^
谎友^ 2020-12-18 07:18

I want to automate a script which verify certain contents in the webpage.

The login page redirected several times before landing on an application page and these re

相关标签:
1条回答
  • 2020-12-18 07:26

    As you mentioned multiple redirection happening and finally the content page is loaded and the script fails mainly due to the wait is pretty much possible. In these cases we need to induce ExplicitWait i.e. WebDriverWait with expected_conditions clause set to either of the following :


    Java :

    1. urlToBe: An expectation for checking the current url is an exact match.

      new WebDriverWait(driver, 10).until(ExpectedConditions.urlToBe("https://www.facebook.com/"));
      
    2. urlContains: An expectation for checking that the current url contains a case-sensitive substring.

      new WebDriverWait(driver, 10).until(ExpectedConditions.urlContains("facebook"));
      
    3. urlMatches: An expectation for checking the current url pattern is the expected pattern which must be an exact match.

      new WebDriverWait(driver, 10).until(ExpectedConditions.urlMatches("my_regex"));
      

    Python :

    1. url_to_be: An expectation for the URL of the current page to be a specific url.

      WebDriverWait(driver, 10).until(EC.url_to_be("https://www.google.co.in/"))
      
    2. url_matches: An expectation for the URL to match a specific regular expression.

      WebDriverWait(driver, 10).until(EC.url_matches("my_regex"))
      
    3. url_contains: An expectation for the URL of the current page to contain specific text.

      WebDriverWait(driver, 10).until(EC.url_contains("google"))
      
    4. url_changes: An expectation for checking the current url which must not be an exact match.

      WebDriverWait(driver, 10).until(EC.url_changes("https://www.google.co.in/"))
      
    0 讨论(0)
提交回复
热议问题