admin管理员组文章数量:1431912
<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);
}
}
本文标签: javascriptSelenium get all inner text of an element with ProtractorStack Overflow
版权声明:本文标题:javascript - Selenium get all inner text of an element with Protractor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745594537a2665396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论