addArguments(以. .ChromeOptions的参数)方法给出错误



对于下面使用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'

build.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)

Chrome版本:

Google Chrome 93.0.4577.63

Chrome Driver Version:

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'

Reference:
无法为RemoteWebDriver设置maven依赖

addArguments方法不是将字符串作为参数,而是接受参数作为参数列表。以下是我所做的,并且也工作了