當appium的UIAutomator中的列表視圖中的兩個元素的資源ID是相同時要做什麼?當兩個元素在appium中具有相同的資源ID時該怎麼辦?
在這裏下面的圖片: -
兩個元素都具有相同的資源ID:-net.one97.paytm:ID/smart_list_root
當appium的UIAutomator中的列表視圖中的兩個元素的資源ID是相同時要做什麼?當兩個元素在appium中具有相同的資源ID時該怎麼辦?
在這裏下面的圖片: -
兩個元素都具有相同的資源ID:-net.one97.paytm:ID/smart_list_root
在這種情況下,你可以使用XPath或名稱象下面這樣:
方法1:
driver.findElement(By.xpath("//android.widget.TextView[@text='Mobile Prepaid']"));
driver.findElement(By.xpath("//android.widget.TextView[@text='Mobile Postpaid']"));
方式2:
driver.findElement(By.name("Mobile Prepaid"));
driver.findElement(By.name("Mobile Postpaid"));
獲取文本使用XPath:
String text = driver.findElement(By.xpath("//android.widget.RelativeLayout")).getText();
比較文本並選擇正確的UIElement來執行所需的操作。
if(text.equals("Mobile Prepaid")){ ...... }
多個元素的XPath的TextView把它當作
"//android.widget.TextView[@text='Mobile Prepaid']"
希望它會工作
您可以使用By.name
一樣,
driver.findElement(By.name("Mobile Prepaid"));
driver.findElement(By.name("Mobile Postpaid"));
這是行不通的,它顯示無效的選擇器 –
隨着Appium 1.5名稱選擇器被刪除。如果您使用1.5,請使用driver.findElement(By.xpath(「// android.widget.TextView [@ text ='Mobile Prepaid']」)) –
方法是正確的,但它沒有點擊那個元素 –