0

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Urban
  • 585
  • 2
  • 13
  • 28

2 Answers2

3

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"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you very much. Selenium is new to me. Thanks to your answer I found a way to achieve my goal. – Urban Feb 16 '18 at 15:56
0

In my case previously I was using below one in pom.xml

     <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-java</artifactId>
         <version>3.141.59</version>
     </dependency>

I removed the above one and replaced with this

      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>3.0.1</version>
          <scope>compile</scope>
      </dependency>

It worked and "until(java.util.function.Function) in FluentWait cannot be applied to" this error gone from my intellij class.

Something is deprecated or not working in newer selenium jar version. so use old one.

You can also add following dependency specifically in pom.xml and check.

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>3.0.1</version>
    </dependency>
rodolfoksveiga
  • 1,181
  • 4
  • 17