gpt4 book ai didi

java - StaleElementReferenceException : Element not found in the cache - perhaps the page has changed since it was looked up Command duration or timeout

转载 作者:行者123 更新时间:2023-12-01 09:33:23 24 4
gpt4 key购买 nike

AT line 106我收到此异常。请解决它。org.openqa.selenium.StaleElementReferenceException:在缓存中找不到元素 - 也许页面自查找以来已更改命令持续时间或超时:5.10 秒

代码:

 List<WebElement> select_year = driver.findElements(By.xpath("//ul[@class='uib-datepicker-popup dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span"));
for(WebElement ele: select_year)
{

String fyear=ele.getText();
if((syear).equals(fyear))
{
System.out.println(syear);
System.out.println(fyear);
ele.click();
List<WebElement>select_month=driver.findElements(By.xpath("//ul[@class='uib-datepicker-popup dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span"));
for(WebElement ele2:select_month)
{
String fmonth=ele2.getText();
if((smonth).equals(fmonth))
{
ele2.click();
List<WebElement>select_day=driver.findElements(By.xpath("//ul[@class='uib-datepicker-popup dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span"));
for(WebElement ele3:select_day)
{
String fday=ele3.getText();
Thread.sleep(3000);
if((sday).equals(fday))
{
ele3.click();

}
}
}
}
}
}

最佳答案

这里不需要循环。您需要找到带有文本的单个元素并选择如下:-

//To select year
driver.findElement(By.xpath("//ul[@class='uib-datepicker-pop‌​up dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span[text() = " + syear+"]")).click();

//To select month
driver.findElement(By.xpath("//ul[@class='uib-datepicker-pop‌​up dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span[text() = " + smonth+"]")).click();

//To select day
driver.findElement(By.xpath("//ul[@class='uib-datepicker-pop‌​up dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span[text() = " + sday+"]")).click();

编辑:-如果你想在这里循环,你只需要在if条件成立时break循环,如下所示:-

//To select year
List<WebElement> select_year = driver.findElements(By.xpath("//ul[@class='uib-datepicker-popup dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span"));
for(WebElement ele: select_year)
{
String fyear=ele.getText();
if((syear).equals(fyear))
{
ele.click();
break;
}
}

//To select month
List<WebElement> select_month = driver.findElements(By.xpath("//ul[@class='uib-datepicker-popup dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span"));
for(WebElement ele: select_year)
{
String fmonth = ele.getText();
if((smonth).equals(fmonth))
{
ele.click();
break;
}
}

//To select day
List<WebElement> select_day = driver.findElements(By.xpath("//ul[@class='uib-datepicker-popup dropdown-menu ng-scope']/li/div/table/tbody/tr/td/button/span"));
for(WebElement ele: select_year)
{
String fday = ele.getText();
if((sday).equals(fday))
{
ele.click();
break;
}
}

关于java - StaleElementReferenceException : Element not found in the cache - perhaps the page has changed since it was looked up Command duration or timeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39217490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com