In selenium test automation, sometimes, when clicking on 'external' pdf links, I see the pdf load in a new window, and it seems to have a reasonable/readable URL in the address bar. However, when using driver.getCurrentUrl()
, the return value is something like chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html
. Any way to force the selenium driver to give me the actual url?
In selenium test automation, sometimes, when clicking on 'external' pdf links, I see the pdf load in a new window, and it seems to have a reasonable/readable URL in the address bar. However, when using driver.getCurrentUrl()
, the return value is something like chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html
. Any way to force the selenium driver to give me the actual url?
- I've never seen that... are you sure you are in the right window? You need to post a minimal reproducible example so we can repro the issue. – JeffC Commented Jan 23 at 23:31
- Thank you for the clue. I'm not convinced I am getting the window handles back from the selenium driver in the order expected. driver.getWindowHandles() returns a Set, and I had been able to reliably iterate through the set in the order in which members were added, but that does not seem to completely hold true with selenium-server-4.27.0, but haven't tested enough to be sure. Either way, I am able to ignore the handles with URLs that contain 'chrome-extension', and fish out the handle I want, and pull the URL from that one. – JackhammersForWeeks Commented Jan 24 at 1:25
1 Answer
Reset to default 0See comment above. Was getting inconsistent return values from driver.getWindowHandles() which was causing the wrong window to be switched to.