Below code is not woking with Chrome browser

96 Views Asked by At

enter image description hereI have created a reusable function which clicks the check box of a particular row and returns the text of that row.

CheckBoxXpath-> private static final String XPATH_JOBRATECATEGORIES_CHECKBOX_LIST = "//kendo-grid-list//table/tbody/tr/td[1]/label";

RowXpath -> private static final String XPATH_JOBRATECATEGORIES_LIST = "//kendo-grid-list//table/tbody/tr/td[2]//div//div";

count-> 0 (I want to click only first row check box)

public String Select_CheckBox_Return_SelectedText(String CheckBoxXpath,String RowXpath, int Count) {
  
  List<WebElementFacade> listOfCheckBox = findAll(By.xpath(CheckBoxXpath));
  List<WebElementFacade> listOfrow = findAll(By.xpath(RowXpath));
  if(listOfCheckBox.size()>Count) {
  for (int i = 0; i <= Count; i++) {
   listOfCheckBox.get(i).click();
   String Actual=listOfrow.get(i).getText();
   
  }
  }else {
   Assert.fail("Need to have more rows to fullfill the requirement");
   return null;
  }
  
  return Actual;
  
 }

This is working fine with Firefox browser, but not working with Chrome browser. On debugging code is throwing exception on -> "listOfCheckBox.get(i).click();" I am not able to understand why it is behaving so weired. Need help. Thanks in advance.

1

There are 1 best solutions below

6
Greg Burghardt On

You need to target the checkboxes, not the labels in your xpath:

//kendo-grid-list//table/tbody/tr/td[1]/input[@type='checkbox']