0

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.

B123
  • 45
  • 1
  • 2
  • 11
  • It could have many reasons depending on the Code of the page you are testing. What is the exact error message you get from the exception? – David J Feb 20 '20 at 13:03
  • 'element not visible' error is displayed – B123 Feb 20 '20 at 13:08
  • Probably your DOM for Chrome/Firefox is not in the same state at this point in time when you trying to execute your code. Make sure some possible JavaScript involved is done before you try to run your code. – David J Feb 20 '20 at 13:10

1 Answers1

1

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

//kendo-grid-list//table/tbody/tr/td[1]/input[@type='checkbox']
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • Tried using explicit wait.....still not working. Can "::before" be clicked with the help of selenium. – B123 Feb 21 '20 at 10:18
  • Taking the Xpath till 'label' that i.e. private static final String XPATH_JOBRATECATEGORIES_CHECKBOX_LIST = "//kendo-grid-list//table/tbody/tr/td[1]/label"; is not clicking the Checkbox. Instead i have to take the Xpath till '::before'. But don't know how to use '::before' in relative Xpath's. Tried using preceding, following, Following-sibling. But i am not able to figure it out. Need help on this – B123 Feb 21 '20 at 10:27
  • @B123: So the xpath is what you are having problems with, then? – Greg Burghardt Feb 21 '20 at 12:08
  • I haven't the foggiest clue what that `::before` psuedo element is. I'm expecting to see an `` tag for the checkbox. Can you post the HTML and CSS that is styling the tags in that part of the page? – Greg Burghardt Feb 21 '20 at 12:10
  • Yes Xpath seems to be the problem. How to click ::before using selenium. – B123 Feb 21 '20 at 12:27
  • @B123: I see. I rewrote my answer. – Greg Burghardt Feb 21 '20 at 15:06