0

I am trying to Identify Elements of the page. I have table and there is lot of rows with multiple Inputs. How to access Input from table rows?

This is my java class

public class Setting extends Page {

    /**Identify Elements of the page*/

    @FindBy(id="table-settings")

    private WebElement Table;

    //Constructor
    public Setting()
    {
        /**Initialize PageFactory WebElements*/
        PageFactory.initElements(driver, this);
    }   

}

2 Answers 2

1

Refer below code, make changes accordingly, Let me know if you find any hurdle in it

@Test
public void test() {
    WebElement Webtable=driver.findElement(By.id("TableID")); // Replace TableID with Actual Table ID or Xpath

    List<WebElement> TotalRowCount=Webtable.findElements(By.xpath("//*[@id='TableID']/tbody/tr"));

    System.out.println("No. of Rows in the WebTable: "+TotalRowCount.size());
    // Now we will Iterate the Table and print the Values   

    int RowIndex=1;

    for(WebElement rowElement:TotalRowCount)
    {
        List<WebElement> TotalColumnCount=rowElement.findElements(By.xpath("td"));
        int ColumnIndex=1;

        for(WebElement colElement:TotalColumnCount)
        {
            System.out.println("Row "+RowIndex+" Column "+ColumnIndex+" Data "+colElement.getText());
            ColumnIndex=ColumnIndex+1;
        }
        RowIndex=RowIndex+1;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this: You can try with finding the specific input element with xpath instead of id. If id available for specific element, you can use id itself. Also in your constructor, try to change your code from

public Setting()
{
    /**Initialize PageFactory WebElements*/
    PageFactory.initElements(driver, this);
}   

to

public Setting(WebDriver driver)
{
  this.driver = driver;
    /**Initialize PageFactory WebElements*/
    PageFactory.initElements(driver, this);
}   

and in your class try adding

WebDriver driver;

before your @FindBy statement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.