4

I'm using Maven and Intellij, project set for jdk-12.0.2, maven in pom 1.8 and when trying to run this code :

WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement el =  wait.until(ExpectedConditions.elementToBeClickable(By.linkText("https://poczta.wp.pl")));

I get :

Error:(37, 30) java: cannot access java.util.function.Function class file for java.util.function.Function not found

Pointing to 'wait'

Tried changing maven in pom from 1.7 to 1.8. > Invalidate cache/Restart

Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
Simon S
  • 43
  • 1
  • 1
  • 7

2 Answers2

7

Given you have maven tag my expectation is that your project is being managed by Maven hence built by Maven Compiler Plugin so your IDE language level settings might derive from what is defined in the pom.xml

I would recommend setting project language level in:

  1. Maven pom.xml file like:

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>    
    
  2. In Idea on Project Properties page you can choose the Language Level for each module

    enter image description here

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • This can also be related to corrupted dependencies, in that case, it can be fixed by removing your .m2/corrupted-file-path Like this https://stackoverflow.com/a/28555124 – Rabhi salim Jun 19 '20 at 10:50
2

I was having same problem, created project using JDK 11 but project setting was still using Language 7 (Ctrl + Shift + Alt + S)

Using selenium version 3.141.59

Below were my original settings

enter image description here enter image description here

Got it fixed by

  1. Adding below to pom.xml inside build section but after pluginManagement

    <plugins><plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
      <source>8</source>
      <target>8</target>
    </configuration>
    

changes in pom.xml

  1. Change module setting by (File -> Project Structure or using keyboard shortcut Ctrl + Alt + Shift + S) And change language level to 8 - Lambda, type annotation etc. as shown in below image

enter image description here

Rajnikant
  • 2,176
  • 24
  • 23