第一次报错信息: org.openqa.selenium.InvalidSelectorException: Locator Strategy ‘css selector’ is not supported for this session
之后几次报错信息为:
Exception in thread “main” org.openqa.selenium.WebDriverException: java.net.SocketException: Software caused connection abort: recv failed
Build info: version: ‘3.14.0’, revision: ‘aacccce0’, time: ‘2018-08-02T20:19:58.91Z’
System info: host: ‘LAPTOP-P2A01AH7’, ip: ‘192.168.253.1’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_202’
编程语言 java
相关的解决方案是webdriver导入是appium而不是selenium ,但是我的代码中报错行是 androidDriver。
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
public class AppiumTest {
public static AndroidDriver androidDriver;
public static void main(String[] args) throws MalformedURLException {
// 1.创建配置对象
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
// 2.添加配置
// deviceName 可以找到我们测试的设备
desiredCapabilities.setCapability("deviceName","127.0.0.1:62001");
// platformName 测试平台
desiredCapabilities.setCapability("platformName","Android");
// appPackage 测试包名
desiredCapabilities.setCapability("appPackage","com.netease.cloudmusic");
// appActivity 测试app的启动入口
desiredCapabilities.setCapability("appActivity","com.netease.cloudmusic.activity.LoadingActivity");
// 3.创建驱动
// 传入两个参数: 参数1 appium的通讯地址,传入appium; 参数2 配置对象
androidDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),desiredCapabilities);
// 4. 执行代码
testCloudMusic();
}
public static void testCloudMusic(){
// 登录页需要加载时间才会显示元素,因此需要等待元素加载完毕
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// 1. 点击同意服务条款
androidDriver.findElementById("com.netease.cloudmusic:id/agree").click();
// 跳转页面需要时间加载
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// 2. 找到同意条款checkbox 并点击 勾上
androidDriver.findElementById("com.netease.cloudmusic:id/agreeCheckbox").click();
// 3. 找到立即体验并点击
androidDriver.findElementById("com.netease.cloudmusic:id/trialT").click();
// 跳转页面需要时间加载
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// 4. 找到同意并且点击
androidDriver.findElementById("com.netease.cloudmusic:id/agree").click();
}
}