How to display two list item results as one to obtain multiple results Using Java in selenium webdriver

Here, you need to combine the two list data to print the two list results in a specific format For example, as shown in the figure

This is my code

List<WebElement> ShippingLabel = driver.findElements(By.xpath(" //label[contains(@class,'radio__label')]")); 
 List<WebElement> ShippingPrice = driver.findElements(By.xpath(" //label[contains(@class,'radio__label')]/following-sibling::span")); 

 for (WebElement SLelement: ShippingLabel) {
       System.out.println("Testingl:"+SLelement.getText());
 }
 for (WebElement SPelement1: ShippingPrice) {
     System.out.println("Testinglp:"+SPelement1.getText());
    }

Solution

Why not:

List<WebElement> ShippingLabel = driver.findElements(By.xpath(" //label[contains(@class,'radio__label')]/following-sibling::span")); 

 for (int i = 0; i < ShippingLabel.size(); i++) {
     WebElement ele1 = ShippingLabel.get(i);
     WebElement ele2 = ShippingPrice.get(i);

     System.out.println(ele1.getText() + ":" + ele2.getText());
 }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>