How to Fetch Text from two separate div's with same class name?

后端 未结 2 855
太阳男子
太阳男子 2021-01-25 12:30

I have to fetch two labels \'Text 1\', \'Text 2\' which belongs to same class =\'xyz\', which are located in two div\'s.Structure as shown below.

2条回答
  •  盖世英雄少女心
    2021-01-25 12:43

    You find elements by className and then use getText() to get the text:

    List elements = driver.findElements(By.className("xyz"));
    
    for(WebElement element:elements) {
        System.out.println(element.getText());
    }
    

提交回复
热议问题