<span class="LogoTitle">Management Console</span>
我正在尝试验证“管理控制台”文本是否存在 ,我无法从上面的代码中找到定位器
答案 0 :(得分:2)
根据您共享的 HTML 提取文本管理控制台,您可以使用以下定位器策略:
的XPath :
String myText = driver.findElement(By.xpath("//span[@class='LogoTitle']")).getAttribute("innerHTML");
注意:确保类属性LogoTitle
唯一标识该元素。否则,您必须遍历DOM并引用父标记/节点。
答案 1 :(得分:0)
You can get this by using Xpath, try using follwing-
**Locating Strategy**
//span[contains(@class, 'LogoTitle') and normalize-space(text()) = 'Management Console']
**To Verify Text Present**
//span[contains(@class, 'LogoTitle') and normalize-space(text()) = 'Management Console'].isDisplayed();
or
Write a function which does this for you, if you're using **Page Object Model**
@FindBy(xpath="//span[contains(@class, 'LogoTitle') and normalize-space(text()) = 'Management Console']")
WebElement textManagementConsole;
Public boolean isManagementConsoleTextPresent(){
textManagementConsole.isDisplayed();
}
Public void isManagementConsoleTextPresentTest(){
Assert.assertTrue(isManagementConsoleTextPresent(), "Management Console Text Not Present");
}