-2

强文本我试图使用 pagefactory 处理 POM 中的 webtable 但它的抛出错误

如果我尝试直接粘贴 xpath,否则它不起作用

 @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);

  }

  }}

它在 WebElement actual_xpath = before_xpath +i +actual_xpath; 上引发错误。

其显示 运算符 + 未定义参数类型 WebElement, int

所以我可以处理这个

4

1 回答 1

1

WebElement 不处理,WebElement 本身的串联。这里的 before_xpath、after_xpath 都是 WebElement 本身。

如果你想连接一些你正在寻找的东西(WebElement actual_xpath = before_xpath +i +after_xpath)

应该有 before_xpath、i 和 after_xpath 的字符串数据类型。

因此,您的 WebElement actual_xpath 将具有正确的字符串来定位 Xpath。

此外,字符串的连接应采用正确的 Xpath 格式。

于 2019-02-12T07:41:42.823 回答