元素不再是有效的selenium Java

时间:2017-04-05 15:12:17

标签: java selenium

我正在经历组合中可用的月份,并且在每次迭代时它应该采用文本然后继续下个月。

问题是,在执行月份更改时会出现此错误:

  

线程“main”中的异常   org.openqa.selenium.StaleElementReferenceException:元素为no   更长有效(警告:服务器未提供任何堆栈跟踪   信息)

//Select the month of June
Select combomes = new Select(driver.findElement(By.id("sel_Mes")));
combomes.selectByIndex(j);              

//Select the year 2016
Select comboano = new Select(driver.findElement(By.id("sel_Ano")));
comboano.selectByValue("2016");

//Click the browse button
driver.findElement(By.id("btn_Consultar")).click();

//Wait for the data to load on the page
WebDriverWait contas = new WebDriverWait(driver, 15);

contas.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.
id("dvPrincipal"))); 

//Get the dvPrincipal text

System.out.println(driver.findElement(By.id("dvPrincipal")).getText());

//Now do the same for the next month: July / 2016.
//Until you arrive in December / 2016

}

image 重试,在DOM更新后找到元素。 我注意到它在更新页面后没有更改名称,但遗憾的是找不到它。

//Select the combo that contains the months 
Select combomeses = new Select(driver.findElement(By.xpath("//*[@id='sel_Mes']")));

 //Lists the options of the combo that contains the months
List<WebElement> dd = combomeses.getOptions();

//Prints the number of combo options that contain the months
System.out.println(dd.size());

//Let's start with the month of June/2016
for (int j = 5; j < 12; j++) {
System.out.println(dd.get(j).getText());


//Select the month of June
Select combomes = new Select(driver.findElement(By.xpath("//*[@id='sel_Mes']")));
combomes.selectByIndex(j);              

//Select the year 2016
Select comboano = new Select(driver.findElement(By.id("sel_Ano")));
comboano.selectByValue("2016");

Thread.sleep(4000);

//Click the browse button
driver.findElement(By.xpath("//*[@id='btn_Consultar']")).click();

Thread.sleep(10000);

//Get the dvPrincipal text
System.out.println(driver.findElement(By.id("dvPrincipal")).getText());

Thread.sleep(2000);

driver.navigate().refresh();

Thread.sleep(5000);

//Re-access the primary URL
driver.get(urlprincipal);   

//Re-access the URL from which the information will be extracted.
driver.get(prestacaodecontas);
}

0 个答案:

没有答案