[Selenium][Java][PageObject]如何检查我们是否有';xyz';列表中的值(Web元素的值)是否包含值?

[Selenium][Java][PageObject]如何检查我们是否有';xyz';列表中的值(Web元素的值)是否包含值?,java,testing,selenium-webdriver,automated-tests,pageobjects,Java,Testing,Selenium Webdriver,Automated Tests,Pageobjects,我创建了一个添加xyz1、xyz2、xyz3…xyz(n)元素的测试,该元素在页面上显示为列表我需要确保在这些名称中存在名为“xyz3”的元素。(或标题不同,我将定义什么) 我的想法是构建list/array/collection,它将收集web元素的所有值,然后我需要编写一个方法,在list中收集的这些值中查找我定义的“xyz3”。 我的web元素: @FindBy(how=how.XPATH,using=“//div[@id='''u field']”) 姓名公开名单; 我创建列表的尝试:

我创建了一个添加xyz1、xyz2、xyz3…xyz(n)元素的测试,该元素在页面上显示为列表我需要确保在这些名称中存在名为“xyz3”的元素。(或标题不同,我将定义什么) 我的想法是构建list/array/collection,它将收集web元素的所有值,然后我需要编写一个方法,在list中收集的这些值中查找我定义的“xyz3”。 我的web元素:

@FindBy(how=how.XPATH,using=“//div[@id='''u field']”)
姓名公开名单;
我创建列表的尝试:
LList myElements=createValTemplateLocators.getListOfNames();
布尔temp1;
for(WebElement e:myElements){
System.out.println(e.getText()+);
}
for(WebElement e:myElements){
temp1=e.getText().contains(“temp1”);
if(temp1==true)System.out.println(“hurray temp1在第页”);
else{System.out.println(“temp1出错”);}
}
控制台中的结果:

我无法创建更好的定位器-更合适的,不会“采取”它旁边的元素。。。 此外,我想知道列表中是否存在“temp1”至少一个,关于每个实体的信息消息不是必需的。。。。 对于我的测试,我没有更好的想法,将来我想在这个案例中使用断言

我是初学者:(而且我大部分时间都在自学,所以有人能帮我解决这个问题吗


(来自波罗的海的问候:)

尝试使用xpath
“//div[@id=''u field']/span”
谢谢您的回答。不幸的是,它以相同的结果结束“-temp1”“no”…What
createValTemplateLocators.getListOfNames()做什么?
  @FindBy(how = How.XPATH, using = "//div[@id='_field']")
public List <WebElement> listOfNames;

My attempts in creating a list :

LList<WebElement> myElements = createEvalTemplateLocators.getListOfNames();
    boolean temp1;
    for(WebElement e : myElements) {

        System.out.println(e.getText() + "");

    }

    for(WebElement e : myElements) {

        temp1 = e.getText().contains("temp1");

        if (temp1==true) System.out.println("hurray temp1 is on page ");
        else {System.out.println("something gone wrong with temp1");}
    }