我无法在Salesforce(CRM应用程序)页面上获取图像元素的工具提示文本。字段旁边有一个帮助图标,当用户将鼠标悬停在该图标上时,将显示一条消息
,我想捕获帮助文本并断言它以供验证。
首先,我不能使用.getAttribute(" title "),因为标题属性中没有文本;其次,当我为图像赋予XPath并应用.getText()时,.getText()不起作用。
下面是页面源代码片段
有人能帮我一下吗?
发布于 2018-07-25 23:07:53
你能告诉我为什么.getText()不工作吗?或者,您也可以执行以下操作: 1.提取HTML代码2.将其另存为字符串3.拆分字符串以提取所需文本
请参阅How to get HTML code of a WebElement in Selenium
或
//moving to element which triggers this tooltip
Actions action= new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//td[@class='labelcol']/span[@class='helpButtonOn']"))).build().perform();
//insert wait here
String hovertext=driver.findElement(By.xpath("//td[@class='labelcol']/span[@class='helpButtonOn']/script")).getText();
System.out.println(hovertext);
或
// javascript executor
WebElement element = driver.findElement(By.xpath("//td[@class='labelcol']/span[@class='helpButtonOn']/script"));
String hovertext = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML", element);
System.out.println(hovertext);
https://stackoverflow.com/questions/51520324
复制相似问题