-2

strong textI was trying to handle webtable in POM using pagefactory but its throwing error

if i try nto paste xpath directly but otherwise its not working

 @FindBy (xpath = "//table[@id='userTable']/tbody/tr[")
     WebElement before_xpath;

     @FindBy (xpath = "]/td[2]")
     WebElement after_xpath;



     @FindBy (xpath = "//table[@id='userTable']/tbody/tr")
     List<WebElement> namelist;



     //Intialising PageObjects

     public users_page() {

         PageFactory.initElements(driver, this);


     }


     //Actions


  public void userlist(String nm, String un, String pw, String cpw, String hub) {


        List<WebElement> row =namelist;
           int row_count = row.size();
         System.out.println("Total no of rows " +row_count);

             for(int i=1;i<row_count;i++) {


             WebElement actual_xpath = before_xpath +i +actual_xpath;
             System.out.println("Total  " +actual_xpath);

  }

  }}

It is throwing error on WebElement actual_xpath = before_xpath +i +actual_xpath;.

its showing The operator + is undefined for the argument type(s) WebElement, int

so hw i can handle this

jino
  • 69
  • 1
  • 12
  • Just use String instead of WebElement variable type and assign the FindBy annotation xpath value to it. Why use FindBy for finding an element with a pretty clear wrong xpath. – Grasshopper Feb 12 '19 at 07:37
  • I made all Strings instead of webelement but still not working – jino Feb 12 '19 at 08:26
  • Update your question with your current code and the current error/result. – JeffC Feb 12 '19 at 14:56

1 Answers1

1

WebElement do not handle, Concatenation of WebElement itself. Here before_xpath, after_xpath are WebElement itself.

If you want to concate something as what you are looking for (WebElement actual_xpath = before_xpath +i +after_xpath)

There should be string datatype of before_xpath, i and after_xpath.

So your WebElement actual_xpath, will be have correct String to locate Xpath.

Also, concatenation of String should be in correct format of Xpath.

Ishita Shah
  • 3,955
  • 2
  • 27
  • 51