jsReturnsValue()
The ExpectedConditions of jsReturnsValue()
returns an Object and is defined as:
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()
The ExpectedConditions of visibilityOfElementLocated()
returns the WebElement and is defined as:
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
This error message...
The method until(Function<? super WebDriver,V>) in the type FluentWait<WebDriver> is not applicable for the arguments (boolean, ExpectedCondition<WebElement>)
...implies that the until()
is not appplicable for multiple return types boolean
and WebElement
.
In your usecase,
jsReturnsValue()
returns an Object.
visibilityOfElementLocated()
returns a WebElement.
Solution
If you your usecase is about the visibility of a certain WebElement you can safely ignore the concern for 'document.readyState' equal to "complete" as it would be an overhead. You can find a relevant discussion in Selenium IE WebDriver only works while debugging.
However, to use the until()
for the visibilityOfElementLocated()
for multiple element of similar type of data types you can follow the below example:
Waiting for either of the elements among By.xpath("//span[@id='id1']")
or By.xpath("//span[@id='id2']")
be like:
new WebDriverWait(driver, 10).until(ExpectedConditions.or(
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='id1']")),
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='id2']"))
));
References
You can find a couple of relevant detailed discussions in
Outro
Do we have any generic function to check if page has completely loaded in Selenium