gpt4 book ai didi

java - 合并两个 WebElements 列表

转载 作者:行者123 更新时间:2023-12-02 01:56:27 25 4
gpt4 key购买 nike

无法打印合并列表中的值,因为它会抛出 null!

List<WebElement> DateTime2 = driver.findElements(By.xpath(""));
driver.findElement(By.xpath("")).click();
List<WebElement> DateTime3 = driver.findElements(By.xpath(""));
List<WebElement> DateTime = new ArrayList<>(DateTime2);
DateTime.addAll(DateTime3);
Thread.sleep(2000);
System.out.println("This is for testing the list " +
DateTime.get(2).getText());
System.out.println("This is for testing the list " +
DateTime.get(30).getText());

我希望输出打印日期和时间

最佳答案

这是我使用的一些代码的示例(尽管我对此示例进行了一些更改。这通常是扩展另一个类的一部分。)

int sanitycount= 0;
int ec_Timeout = 10; //seconds to wait for list...
public void RunAction(WebDriver driver, String in_xpath)
{
try
{
wait = new WebDriverWait(driver, ec_Timeout);
List<WebElement> found_elements = new ArrayList<>();
found_elements = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(in_xpath)));

if (!found_elements.isEmpty())
{
// store this array, return an array from function
// or loop through array and add items to more global array..
}

}
catch (Exception e)
{
if (e.getClass().getCanonicalName().equals("org.openqa.selenium.StaleElementReferenceException"))
{
//need to do it again, not finished loading
System.out.println("*****************Stale caught-redoing");
sanitycount++;
if (sanitycount<ec_Timeout * 2)
{
RunAction(driver, in_xpath);
}
System.out.println (e.toString());
}
else
{
System.out.println (e.toString());
}
}
}
RunAction(your_driver, your_xpath);
//set sanitycount back to zero if you run again...

关于java - 合并两个 WebElements 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57396173/

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