0
我试图获得在搜索结果的工具提示文本中www.bigbasket.com,并用下面的代码如何使用Selenium WebDriver获取工具提示文本?
@FindAll({@FindBy(xpath="//*[contains(@id,'product')][not(contains(@style,'display:none'))]/div/span[2]/a")})
List<WebElement> lblProductName;
public String verifySearchResults(WebDriver browser, String productName){
System.out.println(lblProductName.size());
try{
Actions actions = new Actions(browser);
for(WebElement eachElement:lblProductName){
System.out.println(eachElement.getAttribute("href"));
actions.moveToElement(eachElement).perform();
//Actions action = new Actions(driver);
actions.moveToElement(eachElement).build().perform();
WebElement toolTipElement = browser.findElement(By.cssSelector(".uiv2-tool-tip-hover "));
System.out.println("Tooltip text is "+toolTipElement.getAttribute("textContent"));
}
}catch(Exception e){
System.out.println(e.getMessage());
}
return productName;
}
但与上面的代码,我就能得到的只有工具提示文本的第一个搜索结果。您能否帮助我获得所有搜索结果的工具提示文本?
手册要遵循的步骤 1.转到www.bigbasket.com 2.点击跳转和浏览按钮 3.搜索苹果 4.将鼠标移到每个搜索结果,并查看工具提示文本
'actions.moveToElement(eachElement).perform(); //动作动作=新动作(驱动程序);'似乎毫无用处..是否存在或者是一个错字? – nullpointer
请分享您迄今为止得到的输出结果,您可能实际上期待着。 – nullpointer