环境搭建请参照上一篇
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
public class Chat {
public static void main(String[] args) throws InterruptedException, MalformedURLException {
URL url = new URL("http://127.0.0.1:4723/wd/hub");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("platformName", "Android");
cap.setCapability("deviceName","127.0.0.1:52001");
cap.setCapability("appPackage", "com.tencent.mm");
cap.setCapability("appActivity", ".ui.LauncherUI");
cap.setCapability("noReset", "true");//不重置,保存历史记录,跳过登录步骤
AndroidDriver driver = new AndroidDriver(url, cap);
Thread.sleep(6000);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
//点击【微信】标签第一个人员,
driver.findElements(By.id("com.tencent.mm:id/bth")).get(0).click();
Thread.sleep(3000);
driver.findElement(By.className("android.widget.EditText")).click();
Thread.sleep(3000);
// 输入聊天内容
driver.findElement(By.className("android.widget.EditText")).sendKeys("我的Appium");
driver.findElement(By.id("com.tencent.mm:id/b8k")).click();
Thread.sleep(6000);
driver.quit();
}
}