您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

FluentWait类型不是通用的;不能使用参数对其进行参数化 Selenium和Java导致FluentWait类错误

FluentWait类型不是通用的;不能使用参数对其进行参数化 Selenium和Java导致FluentWait类错误

您需要在等待中指定期望的条件,以下是修改后的代码,可以解决您的问题。

码:

import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

public class DummyClass
{
    WebDriver driver;
    @Test
    public void test()
    {
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);

        until(new Function<WebElement, Boolean>() 
        {
            public Boolean apply(WebElement element)
            {
                return element.getText().endsWith("04");
            }

            private void until(Function<WebElement, Boolean> function)
            {
                driver.findElement(By.linkText("Sample Post2"));
            }
        }
    }
}
java 2022/1/1 18:13:57 有524人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶