问题
各位老师能否帮忙看一下这个问题:
appium代码在idea上运行时报错如下,查看本地的文件只到D:/Program Files/apache-maven-3.6.0/maven-repo/org/seleniumhq/selenium/selenium-api/4.17.0/selenium-api-4.17.0.jar就没法再查看了,不知道哪里来的org/openqa/selenium/WebElement.class类文件。
报错信息
java: 无法访问org.openqa.selenium.WebElement
错误的类文件: /D:/Program Files/apache-maven-3.6.0/maven-repo/org/seleniumhq/selenium/selenium-api/4.17.0/selenium-api-4.17.0.jar!/org/openqa/selenium/WebElement.class
类文件具有错误的版本 55.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。
环境
jdk1.8 + maven3.6 + appium 1.18.3
#代码如下#
package com.ceshiren;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SampleTest {
private static AndroidDriver driver;
@BeforeAll
public static void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "Android");
desiredCapabilities.setCapability("appium:platformVersion", "10");
desiredCapabilities.setCapability("appium:deviceName", "MQS0219521001965");
desiredCapabilities.setCapability("automationName", "UiAutomator2");
desiredCapabilities.setCapability("appium:appPackage", "io.cloudgrey.the_app");
desiredCapabilities.setCapability("appium:appActivity", ".MainActivity");
desiredCapabilities.setCapability("ensureWebviewsHavePages", true);
URL remoteUrl = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver(remoteUrl, desiredCapabilities);
}
@Test
public void sampleTest() {
WebElement el5 = (WebElement) driver.findElement(AppiumBy.xpath("//android.view.ViewGroup[@content-desc=\"Echo Box\"]/android.view.ViewGroup/android.widget.TextView[1]"));
el5.click();
WebElement el6 = (WebElement) driver.findElement(AppiumBy.accessibilityId("messageInput"));
el6.sendKeys("hello 2024");
WebElement el7 = (WebElement) driver.findElement(AppiumBy.xpath("//android.view.ViewGroup[@content-desc=\"messageSaveBtn\"]/android.widget.TextView"));
el7.click();
WebElement el8 = (WebElement) driver.findElement(AppiumBy.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.ImageButton"));
el8.click();
}
@AfterAll
public static void tearDown() {
driver.quit();
}
}
依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>appiumwithjdk8</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.1.1</version>
</dependency>
</dependencies>
</project>