我正在尝试下面的代码,但它每次都会抛出相似的结果..让我知道我做错了什么
driver.get("https://www.google.com/search?hl=en&gl=in&tbm=nws&authuser=0&q=The+Telegraph%27s+Production+Manager+To+Take+Over+The&gws_rd=ssl");
java.util.List<WebElement> competitor_name = driver.findElements(By.className("slp"));
for (int i = 0; i < competitor_name.size(); i++)
{
String cmp_name = competitor_name.get(i).findElement(By.xpath("//span[@class='_tQb _IId']")).getText();
System.out.println("Competitor name is : "+cmp_name );
}
答案 0 :(得分:0)
你能尝试下面的方法来构建正确的xpath,以便我们摆脱这个问题
String cmp_name = competitor_name.get(i).findElement(By.xpath("span[@class='_tQb _IId']")).getText();