使用Selenium WebDriver获取当前页面的URL [英] Getting the URL of the current page using Selenium WebDriver
问题描述
我正在尝试获取当前打开页面的网址。我正在使用Selenium WebDriver和Java。
I'm attempting to get the URL of the currently open page. I am using Selenium WebDriver and Java.
我通过以下方式访问当前网址:
I am accessing the current URL via:
WebDriver driver = new WebDriver();
String url = driver.getCurrentUrl();
但是,该网址似乎并未实际反映我目前所处的位置。
however, the URL does not appear to actually reflect where I currently am.
我目前的测试案例包括访问NYT网站,然后点击技术链接。但是, url
似乎总是 http://www.nytimes.com/
,无论是哪个URL显示在地址栏中。
My current test case involves going to the NYT website and then clicking on the "Technology" link. However, url
appears to always be http://www.nytimes.com/
, regardless of the URL that is displayed in the address bar.
如何实际访问地址栏中URL的值,以便我可以告诉我实际上在哪个页面?
How do I actually access the value of the URL that's in the address bar so I can tell what page I'm actually on?
推荐答案
放睡觉。它会工作。我试过了。
原因是页面尚未加载。
查看此问题以了解如何等待加载 - 等待页面加载Selenium
Put sleep. It will work. I have tried. The reason is that the page wasn't loaded yet. Check this question to know how to wait for load - Wait for page load in Selenium
这篇关于使用Selenium WebDriver获取当前页面的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!