Java 我正在尝试获取我所在页面的url,但我可以';T
每一个链接都在工作,但是“getCurrentUrl()”当它到达这个位置时,代码就停止了,页面甚至没有关闭。 我还尝试使用Java 我正在尝试获取我所在页面的url,但我可以';T,java,selenium,selenium-webdriver,selenium-chromedriver,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,每一个链接都在工作,但是“getCurrentUrl()”当它到达这个位置时,代码就停止了,页面甚至没有关闭。 我还尝试使用String currentUrl=driver.getCurrentUrl()
String currentUrl=driver.getCurrentUrl()但是它不起作用,有人知道我该怎么做吗?
(我是Selenium和编程方面的新手)首先,您应该在driver.navigate()到(url)之间添加一个延迟代码>和驱动程序.getCurrentUrl()代码>以允许加载页面。
现在driver.getCurrentUrl()
以字符串形式返回一个值,这样您就可以按照System.out.println(“当前URL:+driver.getCurrentUrl())所述打印它代码>
然后添加driver.quit()
退出正如@prophet所提到的,您的驱动程序.quit()代码>放错了位置。
另外,driver.getCurrentUrl()代码>返回字符串。所以,除非你接受某个变量中的值并将其打印出来,否则你将不知道它在做什么。
因此,请执行以下操作:
public class WorkingWithChrome {
ChromeDriver driver;
String url = "http://qatechhub.com";
String urlface = "https://www.facebook.com/";
public void invokeBrowser() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\fabio\\eclipse-workspace\\libs\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get(url);
}
public void invokeBrowser2() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\fabio\\eclipse-workspace\\libs\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get(url);
driver.navigate().to(urlface);
driver.navigate().to(url);
driver.getCurrentUrl();
}
public static void main(String[] args) throws Exception {
WorkingWithChrome wc = new WorkingWithChrome();
wc.invokeBrowser();
wc.invokeBrowser2();
}
driver.quit();
}
}
}对不起,我没有正确解释自己,问题出在驱动程序中。getCurrentUrl()
dosnet提供了测试未完成的站点的Url,我很忙:)谢谢你,它成功了:D
public void invokeBrowser2() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\fabio\\eclipse-workspace\\libs\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get(url);
driver.navigate().to(urlface);
driver.navigate().to(url);
System.out.println("Current URL : " + driver.getCurrentUrl());
driver.quit();