从Selenium和JAVA中的特定标记获取内容

从Selenium和JAVA中的特定标记获取内容,java,selenium,Java,Selenium,我在以下方面遇到了一个小问题: 考虑以下代码: <div data-v-2f952c88="" class="text"> <section data-v-3b70ad5b="" data-v-2f952c88="" data-content-provider="OTS" class="description__section">

我在以下方面遇到了一个小问题:

考虑以下代码:

<div data-v-2f952c88="" class="text">
 <section data-v-3b70ad5b="" data-v-2f952c88="" data-content-provider="OTS" class="description__section">        
    SOMETHING
 </section>
</div>
<div data-v-1343242dd="" class="text">
 <section data-v-2232lfd="" data-v-3fgssder="" data-content-provider="HTB" class="description__section">
    SOMETING ELSE
  </section>
</div>

某物
别的
如何使用Selenium在Java中提取代码中所有标记“data content provider”中的所有内容,这样最终我就可以得到这样的字符串

字符串结果=“OTS,HTB”


谢谢

您可以参考以下代码以获得所需的输出:

List< WebElement > list=driver.findElements(By.xpath("//section"));
for(WebElement l : list)
        {
            String text=l.getAttribute("data-content-provider");
            System.out.println(text);
        }
ListList=driver.findElements(By.xpath(“//section”);
for(WebElement l:list)
{
String text=l.getAttribute(“数据内容提供程序”);
System.out.println(文本);
}
//获取所有节元素
列表节=driver.findElements(按.tagName(“节”));
//新的空字符串列表
List dataContentProviders=new ArrayList();
//将所有数据内容提供程序值收集到dataContentProviders
对于(WebElement节:节){
添加(section.getAttribute(“数据内容提供程序”);
}

到目前为止你做了什么?你必须循环使用。在元素上获取属性(“数据内容提供者”)。
列表=…
?如预期:-)请将asnwer标记为helpfull。谢谢
// get all section elements
List<WebElement> sections = driver.findElements(By.tagName("section"));

// new empty list of strings
List<String> dataContentProviders = new ArrayList<String>();

// collect all the data-content-provider values to dataContentProviders 
for (WebElement section: sections) {
     dataContentProviders.add(section.getAttribute("data-content-provider");
}