警告:[未检查] 在创建自定义 Selenium ExpectedConditions 时未检查方法调用

warning: [unchecked] unchecked method invocation on creating a a custom Selenium ExcpectedCondition

我正在尝试使用以下代码创建自定义 Selenium 显式等待

class TabsOpened implements ExpectedCondition {     
int expectedTabs;
  
public TabsOpened(int exp) {
  this.expectedTabs = exp;  
}
  
@Override
public Boolean apply(Object driver) {       
  ArrayList<String> allWindowHandles = new ArrayList<> (((WebDriver)driver).getWindowHandles()); 
  return allWindowHandles.size()== this.expectedTabs;
} 
}

然后

wait.until(new TabsOpened(2));

但我在编译时收到这些警告

Note: Tests.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

使用 -Xlint:unchecked 标志编译我得到

Tests.java:116: warning: [unchecked] unchecked method invocation: method until in class FluentWait is applied to given types
            wait.until(new TabsOpened(2));  // Wait 3 seconds or until 2 tabs are opened
                      ^
  required: Function<? super T,V>
  found: TabsOpened
  where T,V are type-variables:
    T extends Object declared in class FluentWait
    V extends Object declared in method <V>until(Function<? super T,V>)
Tests.java:116: warning: [unchecked] unchecked conversion
            wait.until(new TabsOpened(2));  // Wait 3 seconds or until 2 tabs are opened
                       ^
  required: Function<? super T,V>
  found:    TabsOpened
  where T,V are type-variables:
    T extends Object declared in class FluentWait
    V extends Object declared in method <V>until(Function<? super T,V>)

关于如何解决这个问题的任何想法?我正在使用硒 2.53

我不熟悉这个框架,但是根据javadoc of the interface you are extending,你应该写implements ExpectedCondition<Boolean>并且重写方法的参数应该是WebDriver类型,而不是Object.