具有定制条件的硒中的流变液-铬

问题描述 投票:0回答:1

我面临一个问题,我想创建一个函数,等待列表中的文本“ Other”存在。我希望它等待30秒,然后每5秒它将再次进行呼叫并验证新列表。(最多5到6次,以验证文本是否在新列表中)。我已经通过将List转换为地图并检查所有匹配项(地图转换和检查正在工作)来完成验证。

问题出在等待机制上,我尝试创建复杂的流畅的等待,如果找到期望的文本,该等待也会收到布尔值,然后等待应该停止。但是我不知道如果在第一次或第二次尝试中找不到该文本时该返回什么,我希望它仍然等待并再次调用并再次验证。

  • 我只希望在两种情况下停止等待:

    • 单词“ Other”存在-在这种情况下isExists为true。
    • 经过的时间超过30秒。拉动间隔为5秒,并且未显示单词“ other”

是否可以设置等待Boolean == true的等待条件?我不确定条件Boolean>()是否正确,是否可以在wait.until中完成,如果可以工作

public void testrIntegrationfluent ()
{
    WebElement element = BasePage.getWebElementByXPathWithWaitToClicable("//nz-select[@formcontrolname='selectedIntegrationTypes']/div");
    element.click();
    WebDriver driver2 = WebDriverMgr.getDriver();

    Wait wait = new FluentWait(driver2)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);

    wait.until(new Function<WebDriver , Boolean>() {
        public Boolean apply (WebDriver driver2) {

                List<WebElement> dropdownOptions = driver2.findElements(By.xpath("//ul[contains(@class, 'ant-select-dropdown-menu')]/li"));
                Boolean  isExists = dropdownOptions.stream().map(WebElement::getText).anyMatch(text -> "Other".equals(text));
                if (isExists.equals(true)) {
                    return isExists;
                }
        return  ****** need to think what to put thatkeep waiting and perform  call for list and validation reoccured ******
    }

});
}
selenium selenium-chromedriver webdriverwait fluentwait
1个回答
0
投票

您可以使用声明的FluentWait这样简化您的代码。您可以仅用此行替换包含wait.until(new Function<WebDriver , Boolean>()功能的整个apply块。您可以编写函数以直接查找带有文本lili,而不是调用映射以获取所有Other元素的文本并检查其他文本。

fluentWait.until
    (ExpectedConditions.presenceOfElement(By.xpath("//ul[contains(@class, 'ant-select-dropdown-menu')]/li[text()='Other'])));

此代码将等待,直到包含文本liOther出现。

© www.soinside.com 2019 - 2024. All rights reserved.