How to show two list items in one, for multiple results. Using java in selenium Webdriver

Here you need to print two list results in a specific format, combining the two data lists. For example: as shown in the image
Normal (5-7 days): rupees. 2,400.00
Fast (3-5 days): Rs. 3,000.00
Express (2-3 days): Rs. 3,600.00

enter image description here

Here 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());
    }
+4
source share
1 answer

Why not this:

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 (int i = 0; i < ShippingLabel.size(); i++) {
     WebElement ele1 = ShippingLabel.get(i);
     WebElement ele2 = ShippingPrice.get(i);

     System.out.println(ele1.getText() + ":" + ele2.getText());
 }
0
source

Source: https://habr.com/ru/post/1613301/


All Articles