dimanche 27 mars 2016

Selenium Webdriver: finding checkbox based on multiple row values

Good day,

I went through this site but could not find a solution for my problem and was wondering if people with more experience in Selenium could help me out. Apologies for the long post, but I wanted to make sure that I explained things properly.

I am using Java. I normally use Rational Function Tester (java) but I am trying to see if I can rewrite the code from some of the tests, to see how easy it would be to convert.

I have a table with 11 columns and 4 rows (but it could be 20 or 50 rows, it fluctuates during testing). I can read the table and its content to find the row that I want. I compare each of the first 10 cell values and, if they all match, I want to click on the checkbox that is in column 11. Otherwise, continue to the next row.

The function works properly to retrieve the values from each cell. However, when I try to click on the checkbox, it is always selecting the one that is on the first row. When I checked the attributes, I can see that all the checkboxes have the same 'name' but a different value (such as 1330361, 1330363, 1330359, etc.). Interestingly, if I do a search for all the check boxes in the row, it reports 4 of them (the number found in the whole table, not on the row).

I am probably making a very basic mistake but I cannot figure out what it is.

I use the following code to search in the table. The function receives the table row and, at this point, I am just reporting the cell values then attempt to click on the checkbox that is in the row. It is kind of a debugging function. I am not sure if it is proper to post a huge amount of code, so I will just put a short version of it, where I try to click on each of the checkbox in the table.

// Passing a specific table row to the function:
List<WebElement> columns=myRow.findElements(By.tagName("td"));
for (int iLoop = 0;iLoop < columns.size();iLoop++)
{
     System.out.println("Column " + iLoop + " : '" + columns.get(iLoop).getText().toString() + "'");
     // code to compare actual and expected values and setting of a boolean variable.

     if (iLoop == 10 && recordMatch)
     {
          tCheckbox = myRow.findElement(By.xpath("//input[@type='checkbox']"));
         System.out.println("Value is :" + tCheckbox.getAttribute("value").toString());
          tCheckbox.click();
     }

Thank you,

André




Aucun commentaire:

Enregistrer un commentaire