如何获取Strong标签中的文本。我是我的用户1和用户2.这是HTML:
<div id="socialVertCarPersIm" class="carousel slide">
<div class="carousel-inner vertical">
<div class="item active">
<a href="#/finances/hr/4" target="_blank" class="socImage">
<span style="background:url('http://en.mava-foundation.org/wp-content/uploads/2012/06/Maja-Hoffman_c-Philip-Bermingham-small.jpg') center center no-repeat"></span>
</a>
<a href="#/finances/hr/4" target="_blank" class="socPerson">
<p><strong>User 1</strong></p>
<p></p>
</a>
</div>
<div class="item">
<a href="#/finances/hr/26" target="_blank" class="socImage">
<span style="background:url('https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAazAAAAJDFlZTZlZjFhLTFjYTktNDE1ZS04MDE0LWU0NmEzZTJiMjU4Mw.jpg') center center no-repeat"></span>
</a>
<a href="#/finances/hr/26" target="_blank" class="socPerson">
<p><strong>User 2</strong></p>
<p></p>
</a>
</div>
</div>
</div>
我想用Assert.assertEquals检查名称。这是我的代码:
List <WebElement> names = driver.findElements(By.xpath(".//*[@id='socialVertCarPersIm']//strong"));
ArrayList list1 = new ArrayList();
String name;
for (int i = 0; i<names.size(); i++){
int index = i+1;
name = driver.findElement(By.xpath(".//*[@id='socialVertCarPersIm']//strong" + "[" + index + "]")).getText();
list1.add(name);
System.out.println(name);
}
当我运行我的代码时,控制台中没有任何反应,我想获取用户1和用户2的名称,并使用Assert.assertEquals进行比较,但不知道如何操作。