我有一个字符串,其中包含一些 html 标签,并且一个字符串中有多个数据。我需要检查 UI 上的元素是否存在于该字符串中。我能够删除标签,但我不确定如何将字符串转换为数组或列表,以便更容易比较。
例如,来自数据库的字符串是:
<dl style="float: left; text-align: left; width: 50%;">
<dt>
Note1amp;M
</dt>
<dd>
- This is an example
</dd>
<dt>
Note2
</dt>
<dd>
- Example 2
</dd>
<dt>
Note 3
</dt>
<dd>
- This is example 3
</dd>
来自ui的文本是
Note1 - This is an example
其中 Note1 是一个元素
这是一个例子是另一个元素
到目前为止,我必须删除标签并尝试放入列表
public String[] verifyData(Strint txtFromDB) {
String[] txt = new String[3];
boolean compareValue1 = false, compareValue2 = false;
boolean boolBack = false;
WebElement abbreviation = driver.findElement(By.xpath(itemLocatorP1));
WebElement fullName = driver.findElement(By.xpath(itemLocatorP2));
String p1, p2;
if((abbreviation.isDisplayed()) && (fullName.isDisplayed())) {
try {
getMenu().scroll_To_View_Web_Element(itemLocatorP1);
p1 = getUITxt(itemLocatorP1); // getting a text from the UI;
getMenu().scroll_To_View_Web_Element(itemLocatorP2);
p2 = getUITxt(itemLocatorP2); // getting the second part text from the UI:
txt[0] = p1; // Note 1
txt[1] = p2; // - This is an example
System.out.println("Array txt -> " + txt[0]);
}
catch(Exception e) {
txt[0] = "Blank";
System.out.println("Array txt Exception-> " + txt[0]);
}
所以我想要做的是<dt>Note1</dt> and <dd>-This is an example</dd>作为一个字符串,比如:Note 1 - This is an example在一个列表或数组中,这样我就可以与 UI 上的任何数据进行比较。
偶然的你
慕仙森
相关分类