Java 如何获取类元素中出现的文本
管理控制台 我正在尝试验证管理控制台文本是否存在 ,我无法从上述代码中找到定位器,根据您共享的HTML,要提取文本管理控制台,您可以使用以下定位器策略: XPath:Java 如何获取类元素中出现的文本,java,selenium,Java,Selenium,管理控制台 我正在尝试验证管理控制台文本是否存在 ,我无法从上述代码中找到定位器,根据您共享的HTML,要提取文本管理控制台,您可以使用以下定位器策略: XPath: 注意:确保class属性logotTitle唯一地标识元素。否则,您必须遍历DOM并引用父标记/节点。您的代码试用版如中所示找不到定位器?我的意思是,我不知道如何为上述代码编写定位器。使用字符串获取文本非常有效,谢谢 You can get this by using Xpath, try using follwi
注意:确保class属性logotTitle唯一地标识元素。否则,您必须遍历DOM并引用父标记/节点。您的代码试用版如中所示找不到定位器?我的意思是,我不知道如何为上述代码编写定位器。使用字符串获取文本非常有效,谢谢
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");
}
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");
}