![](/img/trans.png)
[英]Method until(Function) in the type FluentWait is not applicable for the arguments
[英]The method until(Function<? super WebDriver,V>) in the type FluentWait is not applicable for the arguments (boolean, ExpectedCondition<WebElement>)
我已經獲得了兩個條件,基於這些條件,webdriver 在繼續執行之前需要等待其中一個條件滿足。 為此,我將 Explicit wait 與ExpectedConditions.or
一起使用。
我嘗試使用以下代碼:
new WebDriverWait(driver.getDriver(),30).until(
ExpectedConditions.or(
ExpectedConditions.jsReturnsValue("return document.ReadyState")).equals("complete"),
ExpectedConditions.visibilityOfElementLocated(driver.findElement(By.Id("name"))
)
);
我收到錯誤:
The method until(Function<? super WebDriver,V>) in the type FluentWait<WebDriver> is not applicable for the arguments (boolean, ExpectedCondition<WebElement>)
請注意,我使用的是 Guava 23.0,它已經作為依賴項添加到我的 pom.xml
ExpectedConditions.or
接收ExpectedCondition
s 作為參數。 當您將ExpectedConditions.jsReturnsValue
的結果與字符串進行比較時,您將 all 表達式更改為boolean
。
您可以創建自定義ExpectedCondition
來扭曲它
public static ExpectedCondition<Object> customeJsReturnsValue(final String javaScript) {
return new ExpectedCondition<Object>() {
@Override
public Object apply(WebDriver driver) {
return ExpectedConditions.jsReturnsValue("return Spotfire.Busy.idle()")).equals("true")
}
}
}
用途:
new WebDriverWait(driver.getDriver(),30).until(
ExpectedConditions.or(
customeJsReturnsValue("return document.ReadyState")).equals("complete"),
ExpectedConditions.visibilityOfElementLocated(driver.findElement(By.Id("name"))
)
);
jsReturnsValue()
的ExpectedConditions返回一個Object並定義為:
public static ExpectedCondition<java.lang.Object> jsReturnsValue(java.lang.String javaScript)
An expectation for String value from javascript
Parameters:
javaScript - as executable js line
Returns:
true once js return string
visibilityOfElementLocated()
的ExpectedConditions返回WebElement並定義為:
public static ExpectedCondition<WebElement> visibilityOfElementLocated(By locator)
An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.
Parameters:
locator - used to find the element
Returns:
the WebElement once it is located and visible
此錯誤消息...
The method until(Function<? super WebDriver,V>) in the type FluentWait<WebDriver> is not applicable for the arguments (boolean, ExpectedCondition<WebElement>)
...暗示until()
不適用於多種返回類型boolean
和WebElement
。
在您的用例中,
jsReturnsValue()
返回一個Object 。visibilityOfElementLocated()
返回一個WebElement 。如果您的用例與某個WebElement的可見性有關,您可以放心地忽略對“document.readyState”等於“完成”的擔憂,因為這將是一種開銷。 您可以在Selenium IE WebDriver only works while debugging中找到相關討論。
但是,要將until()
用於visibilityOfElementLocated()
用於類似類型數據類型的多個元素,您可以按照以下示例進行操作:
等待By.xpath("//span[@id='id1']")
或By.xpath("//span[@id='id2']")
中的任何一個元素如下:
new WebDriverWait(driver, 10).until(ExpectedConditions.or( ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='id1']")), ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='id2']")) ));
您可以在中找到一些相關的詳細討論
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.