1)。我如何獲得數組/列表中的所有元素值? 2)。我如何點擊元素的值?如何打印多個元素(div)及其值 - Selenium WebDriver in java
<div class="Choice" style="margin-top: -483px;>
<div class="ChoiceEntry Choice_1"> 5</div>
<div class="ChoiceEntry Choice_3"> 10</div>
<div class="ChoiceEntry Choice_2"> 20</div>
<div class="ChoiceEntry Choice_4"> 50</div>
<div class="ChoiceEntry Choice_7"> 75</div>
<div>...</div>
</div>
private static String choiceXPATH =
".//div[@class='Choice']//div[contains(@class,'ChoiceEntry')]";
//此getSize()方法正常工作。
public int getSize() {
waitUntilXXXButtonIsVisible();
List<WebElement> count = getDriver().findElements(By.xpath(XPATH));
return count.size();
}
如何獲取數組/列表中的所有元素值?
public String getAllListValue(){
List<WebElement> list = getDriver().findElements(By.xpath(xpath));
return list.toString();;
}
我想,我會得到像「5,10,20,50,75」字符串數組。 :-)
我的第二個問題是我們如何點擊div元素值或div類名(ChoiceEntry Choice_ {index})?
非常感謝提前。
謝謝,我的結果看起來像這樣。 [10,5,100,75,,,,,,,,],應該有13個元素。我不知道爲什麼一些元素沒有顯示在數組列表中。 – zoram