Home:ALL Converter>method to iterate on table

method to iterate on table

Ask Time:2018-06-08T22:08:51         Author:Anna

Json Formatter

I have a table on website that I need to check if requirements are fulfilled using Selenium.

Number of rows is dynamic - one day it is 3 and one day is 5 rows. I would like to write a method that will check (compare numbers) if Current value is (greater than or equal to Minimum Value) and (smaller than or equal to Maximum Value in each row).

I wrote this method but it is only applicable for one row and checks only minimum.


@FindBy(xpath = "//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[1]/td[3]")
protected WebElement minimumREQ1;

@FindBy(xpath = "//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[1]/td[4]")
protected WebElement actualREQ1;

@FindBy(xpath = "//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[1]/td[5]")
protected WebElement maximumREQ1;

public void checkRow1() {
    if (minimumREQ1.isDisplayed()) {
        for (int i = 1; i < 10; i += 1) {
            String ov1 = minimumREQ1.getText();
            String ov2 = actualREQ1.getText();
            String ov3 = maximumREQ1.getText();
            if (ov1.equals("-")) { ov1 = "0"; }
            if (ov2.equals("-")) { ov2 = "0"; }
            if (ov3.equals("-")) { ov3 = "0"; }
            double doubleOV1 = Double.parseDouble(ov1);
            double doubleOV2 = Double.parseDouble(ov2);
            double doubleOV3 = Double.parseDouble(ov3);
            if (doubleOV2 < doubleOV1) {
                Integer number = firstnumber + i;
                String stringNumber = number.toString();
            } else {

Author:Anna,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762503/method-to-iterate-on-table
Vinit Mehta :

Try this.\n\n List<WebElement> webElement = \n driver.findElements(By.xpath(\"//table[@class=\"qor-table\"]//tbody/tr\"));\n\nfor (int i = 1;i<=webElement.size();i++){\n\nSystem.out.println(\"Minimum \"+driver.findElement(By.xpath(\"//table[@class=\"qor- \ntable\"]//tbody/tr[\"+i+\"]/td[3]\")));\n\nSystem.out.println(\"Current \"+driver.findElement(By.xpath(\"//table[@class=\"qor- \ntable\"]//tbody/tr[\"+i+\"]/td[4]\")));\n\nSystem.out.println(\"Maximum \"+driver.findElement(By.xpath(\"//table[@class=\"qor- \ntable\"]//tbody/tr[\"+i+\"]/td[5]\")));\n\n}\n\n\nHope this help!",