表达式
1.xpath根据text内容查找元素
//view[contains(@text,"value")]
//view[@text="value"]等
2.xpath根据content-desc查找元素
//view[contains(@content-desc,"value")]
3.xpath根据index查找元素
//view[contains(@index,value)]
4.元素顺序
//view/view[n]/view等
例子
以下语句已定位通过
WebElement sells = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,‘正在售票‘)]"));
WebElement movie = driver.findElement(By.xpath("//android.widget.TextView[@text=‘夜孔雀‘]"));
WebElement banner =driver.findElement(By.xpath("//android.support.v7.widget.RecyclerView/android.widget.LinearLayout/android.widget.LinearLayout")) ;
WebElement menu_me = driver.findElement(By.xpath("//*[@resource-id=‘com.gewara:id/side_menu_home‘]/android.widget.TextView"));
原文地址:https://www.cnblogs.com/51testing/p/12098530.html
时间: 2024-10-31 09:15:17