大佬教程收集整理的这篇文章主要介绍了selenium加载页面后获取当前URL,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
就像您说的那样,因为下一个按钮的xpath在每个页面上都是相同的,所以它将不起作用。它按照编码的方式工作,它确实等待元素显示,但是由于已经显示了元素,因此隐式等待不再适用,因为它根本不需要等待。为什么不使用URL更改的事实,因为单击代码后,URL从您的代码看来会更改。我使用C#,但我想在Java中会是这样:
WebDriver driver = new firefoxDriver();
String startURL = //a starting url;
String currentURL = null;
webdriverwait wait = new webdriverwait(driver, 10);
foo(driver,startURL);
/* go to next page */
if(driver.findElement(By.xpath("//*[@ID='someID']")).isdisplayed()){
String prevIoUsURL = driver.getcurrenturl();
driver.findElement(By.xpath("//*[@ID='someID']")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
ExpectedCondition e = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return (d.getcurrenturl() != prevIoUsURL);
}
};
wait.until(e);
currentURL = driver.getcurrenturl();
System.out.println(currentURL);
}
@H_419_4@
我在Java中使用Selenium Webdriver。我想在单击“下一步”按钮从第1页移至第2页后获得当前的url。这是我的代码:
WebDriver driver = new FirefoxDriver();
String startURL = //a starting url;
String currentURL = null;
WebDriverWait wait = new WebDriverWait(driver,10);
foo(driver,startURL);
/* go to next page */
if(driver.findElement(By.xpath("//*[@id='someID']")).isDisplayed()){
driver.findElement(By.xpath("//*[@id='someID']")).click();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='someID']")));
currentURL = driver.getCurrentUrl();
System.out.println(currentURL);
}
我有隐式和显式的等待调用,以等待页面完全加载后再获得当前的url。但是,它仍在打印第1页的网址(应该是第2页的网址)。
以上是大佬教程为你收集整理的selenium加载页面后获取当前URL全部内容,希望文章能够帮你解决selenium加载页面后获取当前URL所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。