简体   繁体   English

'错误:java:无法访问 java.util.function.Function' - 在尝试使用 WebDriverWait 时

[英]'Error: java: cannot access java.util.function.Function' - while trying to use WebDriverWait

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 :我正在使用 Maven 和 Intellij,为 jdk-12.0.2 设置的项目,pom 1.8 中的 maven 以及尝试运行此代码时:

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错误:(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.尝试将 pom 中的 maven 从 1.7 更改为 1.8。 > Invalidate cache/Restart > Invalidate cache/Restart

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 鉴于您具有maven标签,我的期望是您的项目由Maven管理,因此由Maven编译器插件构建,因此您的IDE语言级别设置可能源自pom.xml中定义的内容。

I would recommend setting project language level in: 我建议在以下位置设置项目语言级别:

  1. Maven pom.xml file like: Maven pom.xml文件如下:

     <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 在“项目属性的想法”页面中 ,可以为每个模块选择语言级别

    在此处输入图片说明

More information: 更多信息:

I was having same problem, created project using JDK 11 but project setting was still using Language 7 (Ctrl + Shift + Alt + S)我遇到了同样的问题,使用 JDK 11 创建项目,但项目设置仍在使用语言 7(Ctrl + Shift + Alt + S)

Using selenium version 3.141.59使用硒版本 3.141.59

Below were my original settings以下是我的原始设置

在此处输入图像描述 在此处输入图像描述

Got it fixed by得到它修复

  1. Adding below to pom.xml inside build section but after pluginManagement在构建部分的pom.xml中添加以下内容,但在 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>

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通过(文件 -> 项目结构或使用键盘快捷键 Ctrl + Alt + Shift + S)更改模块设置并将语言级别更改为 8 - Lambda,键入注释等,如下图所示

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在硒中发生错误“java:无法访问 java.util.function.Function 的 java.util.function.Function 类文件未找到” - error occurred "java: cannot access java.util.function.Function class file for java.util.function.Function not found " in selenium Selenium Java WebDriverWait - 无法访问 java.util.function - Selenium Java WebDriverWait - cannot access java.util.function 使用java.util.function.Function实现Factory Design Pattern - use java.util.function.Function to implement Factory Design Pattern Java.util.function.Function带参数 - Java.util.function.Function with parameter 将java.util.function.Function转换为Interface - Cast java.util.function.Function to Interface 关于Java泛型和java.util.function.Function设计的问题 - Question about Java generics and design of java.util.function.Function Java 8:用于将Java.util.function.Function实现为Lambda表达式的语法 - Java 8: Syntax for Implementing java.util.function.Function as a Lambda Expression 用于按输入分组的通用 java.util.function.Function - Generic java.util.function.Function for Grouping as per input 将 java.util.function.Function 定义为 ZA81259CEF8E5559C6297DF1D4 - Defining java.util.function.Function as static final 在火花中使用stanford nlp,错误“找不到类java.util.function.Function-继续存根。” - using stanford nlp in spark, error “ Class java.util.function.Function not found - continuing with a stub.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM