I've been trying to extract the URL if the page hasn't finished loading but I want the URL if driver wait time(10 sec) is over and moves to throw a custom exception.
I've tried window.location.href
, window.location.pathname
, etc but they returns null.
Asked
Active
Viewed 588 times
0

undetected Selenium
- 183,867
- 41
- 278
- 352
-
It seems like that Javascript API's don't reflect the current URL until the page is loaded. I've witnessed some odd behavior with iOS when I was debugging early Angular digest cycles where the location property wasn't immediately updated. How are you setting the URL? That would be where I would look. Is this a result of a redirect? How is the browser getting into a state where there's an "unknown" navigation event that wasn't triggered by your webdriver code? – Sean Aitken Mar 07 '19 at 07:12
1 Answers
0
Window Location
The JavaScript window.location
object can be used to get the current page address (URL) and to redirect the browser to a new page. The window.location
object can be written without the window prefix. Some examples:
window.location.href
: returns the href (URL) of the current pagewindow.location.hostname
: returns the domain name of the web hostwindow.location.pathname
: returns the path and filename of the current pagewindow.location.protocol
: returns the web protocol used (http: or https:)window.location.assign
: loads a new document
Page completely not loaded
Unfortunately, there is no generic step to check if page has completely loaded through Selenium. However there are certain approaches to ensure that the page is completely loaded using the following strategies:
pageLoadStrategy
- Wait for the Browser Client attaining 'document.readyState' equal to "complete"
- Induce WebDriverWait inconjunction with ExpectedConditions as:
urlContains()
: The expectation for the URL of the current page to contain specific text.urlMatches()
: The expectation for the URL to match a specific regular expressionurlToBe()
: The expectation for the URL of the current page to be a specific url.
Note: You can find a detailed discussion in Do we have any generic funtion to check if page has completely loaded in Selenium

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