java - ChromeOptions 的 addArguments(java.lang.String... arguments) 方法给出错误
问题描述
对于以下使用 addArguments() 方法设置 chromeoptions 的代码,出现以下错误
cannot access AbstractDriverOptions
options.addArguments("--disable-web-security");
^
class file for org.openqa.selenium.remote.AbstractDriverOptions not found
代码:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-web-security");
options.addArguments("--headless");
options.addArguments("--window-size=2880,1800");
options.addArguments("--start-fullscreen");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-notifications");
...
...
此代码在旧版本的 Selenium 依赖项中运行良好,但现在由于某些原因我将所有依赖项升级到新版本,但它无法正常工作
硒依赖:
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.0.0-rc-1'
implementation 'org.seleniumhq.selenium:selenium-support:4.0.0-rc-1'
构建.gradle:
plugins {
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'org.ajoberstar.grgit' version '3.1.1'
id "com.gorylenko.gradle-git-properties" version "2.3.1"
}
group = 'com.leadmi'
if (project.hasProperty('appVersion')) {
version = "${appVersion}"
} else {
version = "${version}-BRANCH-${grgit.branch.current().name}-SNAPSHOT"
}
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
ext {
set('springCloudVersion', "2020.0.3")
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
implementation 'net.logstash.logback:logstash-logback-encoder:6.6'
testImplementation 'org.springdoc:springdoc-openapi-webmvc-core:1.5.10'
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.60'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
testImplementation 'org.springframework.kafka:spring-kafka-test'
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.0.0-rc-1'
implementation 'org.seleniumhq.selenium:selenium-support:4.0.0-rc-1'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation 'org.apache.commons:commons-collections4:4.4'
implementation 'me.xdrop:fuzzywuzzy:1.3.1'
implementation 'org.jsoup:jsoup:1.14.2'
implementation 'us.codecraft:xsoup:0.3.2'
implementation 'org.springframework.kafka:spring-kafka'
testImplementation 'org.springframework.kafka:spring-kafka-test'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-config'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
我正在使用的 Java 版本:
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
铬版:
Google Chrome 93.0.4577.63
Chrome 驱动程序版本:
93.0.4577.15
解决方案
你错过了以下依赖
implementation 'org.seleniumhq.selenium:selenium-remote-driver:4.0.0-rc-1'
如官方文档所述,一般我们可以只使用
selenium-java
依赖
implementation 'org.seleniumhq.selenium:selenium-java:4.0.0-rc-1'
代替
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.0.0-rc-1'
implementation 'org.seleniumhq.selenium:selenium-support:4.0.0-rc-1'
implementation 'org.seleniumhq.selenium:selenium-remote-driver:4.0.0-rc-1'
推荐阅读
- r - 使用 group_by 和 rleid() 函数创建新变量
- java - 如何从多维数组的用户那里获取输入?
- wordpress - 为什么“wpbakery page builder的终极插件”插件在我激活时会爆炸?
- infinispan-9 - Infinispan 服务器:如何使用它
- python - 提高将 pandas DataFrames 扁平化为 dicts 列表的性能
- android - D8:程序类型已经存在:org.apache.cordova.BuildHelper
- javascript - 未捕获的错误:导出导入时,路由配置中需要 [vue-router] “路径”
- javascript - displaySurface 约束不限制用户共享屏幕选择选项
- python - 评估条件,例如 if 90 <= score <= 100
- hal - 无法为 ArrayObject 类型的对象生成 HalResource