<div class="test"> <span>
<div>TEXT </div>
</span>
<div>
<ul>
<li> <span>Other text</span>
TEST1</li>
<li>TEST2</li>
</ul>
</div>
</div>
How can I get all of the inner text of the div with test class ? Ideally I would like to have an array of string , something like : ["TEXT","Other text","TEST1","TEST2"].
<div class="test"> <span>
<div>TEXT </div>
</span>
<div>
<ul>
<li> <span>Other text</span>
TEST1</li>
<li>TEST2</li>
</ul>
</div>
</div>
How can I get all of the inner text of the div with test class ? Ideally I would like to have an array of string , something like : ["TEXT","Other text","TEST1","TEST2"].
Share Improve this question edited Jul 29, 2015 at 13:41 alecxe 475k127 gold badges1.1k silver badges1.2k bronze badges asked Jul 29, 2015 at 7:11 KarudiKarudi 2,8023 gold badges20 silver badges19 bronze badges 1- I researched it a bit more , I can actually get all of the text with this Xpath expression : ` //*[contains(concat(" ", normalize-space(@class), " "), "test")]/descendant::*/text() ` . The problem is when I use findElements , I get an error saying that the results are not WebElements. – Karudi Commented Jul 29, 2015 at 9:02
2 Answers
Reset to default 3You don't need to use the webdriver methods directly, protractor
has a convenient abstraction around findElements()
- element.all()
. map()
would help to get a promise resolving into an array of texts:
var texts = element.all(by.xpath("//div[@class='test']//*")).map(function (elm) {
return elm.getText();
});
expect(texts).toEqual(["TEXT", "Other text", "TEST1", "TEST2"]);
try something like this:
List<WebElement> list = driver.findElements(By.xpath("//div[@class='test']"));
for(WebElement element: list){
//print text if text not empty
String text = element.getText();
if(!text.isEmpty){
S.O.P("Result :"+text);
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745594537a4635030.html
评论列表(0条)