,将加载新页面。页面加载后,我无法找到页面中的任何元素。我使用了以下代码。我只是没有这样的元素例外。你能帮忙解决这个问题吗?
WebElement element7 = driver.findElement(By.id("linkid"));
if (element7.isEnabled())
{
element7.click();
System.out.println(" Report is selected");
}
testclass.waitForPageLoaded(driver); // using this method i have been waiting the page new page load.
//find the elements in the new page .
WebElement element8 = driver.findElement(By.id("cbPeriodType"));
if(element8.isDisplayed())
{
Select Periodtype = new Select(driver.findElement(By.id("cbPeriodType`enter code here`")));
Periodtype.selectByValue("1");
System.out.println("PeriodTypeSelected");
}
答案 0 :(得分:0)
看起来元素查找太快了。找到元素时使用explicit等待。查看ExpectedConditions here
的完整列表// find the elements in the new page .
//WebElement element8 = driver.findElement(By.id("cbPeriodType"));
WebElement element8 = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("cbPeriodType")));
Select Periodtype = new Select(driver.findElement(element8 ));
Periodtype.selectByValue("1");
System.out.println("PeriodTypeSelected");