最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Selenium, the return value of driver.getCurrentUrl(), for pdfs, get things like 'chrome-extension:mhjfbmdgcfjbbpa

programmeradmin1浏览0评论

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?

Share Improve this question asked Jan 23 at 23:24 JackhammersForWeeksJackhammersForWeeks 9671 gold badge9 silver badges22 bronze badges 2
  • 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
Add a comment  | 

1 Answer 1

Reset to default 0

See comment above. Was getting inconsistent return values from driver.getWindowHandles() which was causing the wrong window to be switched to.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论