这个问题我已经解决了,现在把实现的代码展现一下,希望能帮助到大家,如果大家有更好的方法希望不吝赐教!
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import java.util.Set;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class leizhong {
public AndroidDriver driver;
public leizhong(AndroidDriver driver){
this.driver=driver;
}
@Test
public void swpie() throws Exception{
//获取当前的混合应用类型,判断如果是 webview 跳转进入 webview
Set contextNames = driver.getContextHandles();
for(String contextName : contextNames){
System.out.println(contextName);
if(contextName.contains("WEBVIEW")){
driver=(AndroidDriver) driver.context(contextName);
}else{
System.out.println("no WEBVIEW");
}
}
Thread.sleep(2000);
driver=(AndroidDriver) driver.context("NATIVE_APP");
WebElement loginBtn=driver.findElementByName("社区");
loginBtn.click();
Thread.sleep(20000);
System.out.println("社区");
Thread.sleep(2000);
WebElement loginBtn1=driver.findElementByName("糖友锻炼");
loginBtn1.click();
System.out.println("糖友锻炼");;
Thread.sleep(2000);
try{
File file = new File("d:\test.xls");
InputStream in = new FileInputStream(file);
Workbook workbook = Workbook.getWorkbook(in);
Sheet sheet = workbook.getSheet(0);
int rowLength=sheet.getRows();
System.out.println(rowLength);
for(int i=1;i
Thread.sleep(3000);
driver.findElementByXPath("//android.widget.ImageView[contains(@index,2)]").click();
Thread.sleep(2000);
WebElement title=driver.findElementByName("最多 30 个字");
Cell c10=sheet.getCell(0,i);
String strc10=c10.getContents();
System.out.println(strc10);
title.sendKeys(strc10);
Thread.sleep(20000);
Cell c21=sheet.getCell(1,i);
String strc21=c21.getContents();
System.out.println(strc21);
driver.findElementById("com.qshealthcare.qshc:id/activity_publish_new_main_title_content_et").sendKeys(strc21);
Thread.sleep(2000);
driver.findElementByName("发布").click();
Thread.sleep(1000);
}
}catch(Exception e){
System.out.println("failed!");
}
System.out.println("success");
}
}