appium java 点击坐标_[已解决] Appium+Android 真机 +Java 脚本: 如何实现坐标点的点击、拖拽?以及对控件的拖拽?...

package appium;

import java.net.URL;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

public class sdk_COOLPAD {

private WebDriver driver;

SDK sdk = new SDK("COOLPAD");

@BeforeMethod(alwaysRun = true)

public void setUp() throws Exception {

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("platformName", "Android");

capabilities.setCapability("deviceName", "vivo x5l");

capabilities.setCapability("udid", "BMBY8LU4YTMBS8SO");

capabilities.setCapability("app", sdk.getApk());

capabilities.setCapability("appPackage", sdk.getPkg());

capabilities.setCapability("appActivity", sdk.getActivity());

capabilities.setCapability("unicodeKeyboard", true);

capabilities.setCapability("resetKeyboard", true);

driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

}

@AfterMethod(alwaysRun = true)

public void tearDown() throws Exception {

driver.quit();

}

@Test(groups = { "testCOOLPAD" })

public void testCOOLPAD() throws InterruptedException {

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

driver.findElement(By.xpath("//android.widget.Button[contains(@text,'初始化SDK')]")).click();

Assert.assertTrue(((WebElement) driver.findElement(

By.xpath("//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.TextView[2]")))

.getText().contains("初始化成功"));

driver.findElement(By.xpath("//android.widget.Button[contains(@text,'清空')]")).click();

driver.findElement(By.xpath("//android.widget.Button[contains(@text,'获取网关')]")).click();

Assert.assertTrue(((WebElement) driver.findElement(

By.xpath("//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.TextView[1]")))

.getText().contains("获取网关成功"));

driver.findElement(By.xpath("//android.widget.Button[contains(@text,'清空')]")).click();

driver.findElement(By.xpath("//android.widget.Button[contains(@text,'登录(第一步)')]")).click();

driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'请输入手机号/邮箱')]"))

.sendKeys(sdk.getAccount());

driver.findElement(By

.xpath("//android.widget.ScrollView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.EditText"))

.sendKeys(sdk.getPwd());

//此时, 当前页面并没有显示登录按钮, 需要对屏幕进行上拉操作才能找到并点击登录按钮

driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'登 录')]")).click();

}

}

你可能感兴趣的:(appium,java,点击坐标)