appium 之Xpath使用
来源:互联网 发布:java实例变量 编辑:程序博客网 时间:2024/06/05 06:27
@Test(description="绝对定位”)
public void TestCase1() throws InterruptedException{
Thread.sleep(5000);
WebElement element=wd.findelement(By.xpath("//android.widget.TextView[contains(@text,'热门推荐')]"));
wd.tap(1,element,500);
Thread.sleep(2000);
WebElement BackButton=wd.findElement(By.xpath("//android.wdigrt.ImageButton[contains(@content-desc,'Navigate up')]"))
wd.tap(1,BackButton,500);
}
封装键盘上的keyEvent
public interface EnumCollection{
public class KeyEvent{
public static int KEYEVENT_MOVETOLAST=123;
public static int KEYeVENT_DELETEONELETTER=67;
public static int RETURN_BUTTON=4;
}
public class FingerCount{
public static int ONE_FINGER=1;
public static int TWO_FINGER=2;
}
public class NetWorkStatus{
public static int FLYMODE=1;
public static int WIFIMODE=2;
public static int DATAMODE=4;
public static int ALLMODE=6;
}
}
调用封装方法:
wd.sendKeyEvent(KeyEvent,RETURN_BUTTON);
封装使用2:
public class DataCeneter{
private static String Category_Head="//android.widgt.TextView[contains(@text,'1$s')]";
public static String StringFormat(String StrText){
return String.format(Category_Head,StrText);
}
}
调用封装方法:
WebElement element2=wd.findElement(By.xpath(DataCenetr.StringFormat(StrText)));
xpath识别
eg:driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'电影')]/preceding-sibling::android.widget.ImageView[1]"));
driver.findElement(By.xpath("//andriod.support.v7.widget.RecyclerView/child::android.widget.RelativeLayout[1]"));
driver.findElement(By.xpath("//andriod.support.v7.widget.RecyclerView/child::android.widget.RelativeLayout[last()]"));
driver.findElement(By.xpath("//andriod.support.v7.widget.RecyclerView/child::android.widget.RelativeLayout[last()-1]"));
driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'热门推荐')]/parent::android.widget.RelativeLayout/following-sibling::android.widget.RelativeLayout[1]+"android.widget.TextView[last()]"));
Xpath识别
相对定位-Xpath
1.parent/descendant/following/preceding...
2.
ClassName[location]
3.
UiSelector函数
一.通过判断控件属性获取控件
控件的所有属性都可以用作判断,例如:text,index,resource_id是否可以clickable等
1.通过文本查看目标控件
WebElement el=driver.findElementByXPath("//android.widgt.TextView[contains(@text,'note2')]");
assertThat(el.getText(),equalsTo("note2"));
driver.find_element_by_xpath("//android.widget.ScrollView/android.widget.RelativeLayout[5]/android.widget.TextView[2]").click()
2.通过index查看目标控件
el = driver.findElementByXPath("//android.widget.TextView[contains(@index,0)]"); assertThat(el.getText(),equalTo("note2"));
el = driver.findElementByXPath("//android.widget.LinearLayout[1]/android.widget.FrameLayout/android.widget.ListView/android.widget.TextView[contains(@index,0)]");
assertThat(el.getText(),equalTo("note2"));
appium 屏幕滑动
水平:
driver.swipe(x-100,elementLocation.getY(),100,elementLocation.getY(),2000);
垂直:
driver.swipe(driver.manage().window().getSize().getWidth()-100,y,100,y,2000);
public void TestCase3() throws InterruptedException{
WebElement element=null;
try{
//如果找到element
//swipe
//click
}catch{
continue;
}
}
0 0
- appium 之Xpath使用
- Appium中xpath的使用
- Appium使用之helloworld
- Appium之使用小结
- appium使用xpath相对路径查找元素方法
- appium native xpath
- Appium通过xpath定位
- Xpath之最好使用方式
- Android自动化测试之appium的使用
- Appium之“使用 resource id 定位”
- selenium使用Xpath定位之完整篇
- Appium根据xpath获取控件实例随笔
- Appium根据xpath获取控件实例随笔
- Appium根据xpath获取控件实例随笔
- Appium+robotframework xpath元素定位、难点解决
- xpath使用
- xpath使用
- xpath使用
- hdu 3715 hdu 1816 hdu 4115 (2-sat)
- 572 - Oil Deposits
- 点击A显示,点击其他地方隐藏
- IOS 计算两个时区之间的时间差
- Java设计模式-工厂方法模式和抽象工厂模式
- appium 之Xpath使用
- Android获取View的高度
- Android-Universal-Image-Loader(UIL)源码解析(二)
- caffe accuracy_layer.cpp 解读
- appium之Context切换
- _USER_ERROR__missing_dlib_all_source_cpp_file__OR......
- Android ViewPager放入多个XML如何监听其的控件_程序架构参考
- Tornado编译vxworks本质及过程
- python中用的到奇淫技巧