I have a Selenium test that checks if a certain string can be seen on the testpage. My idea is to use an explicitwait if the page doesn’t load immediately.
WebElement element = driver.findElement(By.xpath("//*[text()='text']"));
After that I did:
WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.visibilityOf(element));
So it has a waiting time of max 10 seconds before continuing. If it sees the element within 10 seconds the test continues.
But i get the following error at the wait.until
until (java.util.function.Function<? super org.openqa.selenium.WebDriver,java.lang.Object>) in FluentWait cannot be applied to (org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement>)
Using google to solve this hasn’t helped me. Anyone knows how to solve this error?
The element contains the String that I want
Advertisement
Answer
As you mentioned in your question to check if a certain string can be seen on the testpage is too broad as a validation point. Ideally you should be validating if the intended text is present within a WebElement or not. To achieve that, you have to use either of the Locator Strategy to identify the element first and then induce WebDriverWait with proper ExpectedConditions to validate the text as follows :
Steps
Locate the WebElement :
WebElement element = driver.findElement(Locator Strategy);
Induce WebDriverWait for textToBePresentInElement :
WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.textToBePresentInElement(element, "text_to_be_validated"));