2016-08-19 232 views

回答

1

您不必使用XPath在上述情況下,因爲你有元素ID 。另外,您要添加index = 0的檢查,這意味着它只會檢查索引爲0的元素。在下面的示例中,我使用ID =「bankType」查找元素並打印其大小。在生成隨機數我已經減去「1」,因爲該指數將從0

List<WebElement> elementList = driver.findElements(By.id("bankType")); 
System.out.println("Total elements : " + elementList.size()); 

Random rand = new Random(); 
int index = rand.nextInt(elementList.size()-1); // -1 because index will start from 0 

elementList.get(index).click(); 
0

用Ruby使用appium這種方式開始,但這個應該是不錯的,如果你有較少的元素,也因爲,兩者的我的元素有不同的xpath的。

And(/^I select the choice in cooking style$/) do 
    style = 
['//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell[1]/UIACollectionView[1]/UIACollectionCell[1]/UIAStaticText[1]]' , '//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell[1]/UIACollectionView[1]/UIACollectionCell[2]/UIAStaticText[1]'] 
    cookingstyle = style.sample 
    find_element(xpath: cookingstyle).click 
    puts cookingstyle 

end 
相關問題