Compare List WebElement with String Array Compare List WebElement with String Array selenium selenium

Compare List WebElement with String Array


If you don't bother about the order, then collect all text from WebElement to List<String>

List<String> text = options.stream().map(WebElement::getText).collect(Collectors.toList());

Then now just compare by using equals()

System.out.println(text.equals(Arrays.asList(verify1));  // use naming convention for variables 

Note This approach is case sensitive


Not really elegant but I thinks it's works

        String[] Verify1 = Verify.split(",");        List<WebElement> options = driver.findElements(By.xpath(SUMMARYFIELDS));        boolean isOK = true;            for (WebElement ele : options) {            int i = Arrays.asList(Verify1).indexOf("string "+ele.getText())            if(i==-1){                 isOK=false;            }            else{                 System.out.println(Verify1[i]" Excel data = "+ ele.getText()+" web list");            }        }