Jonathan
Jonathan

Reputation: 395

skipping first row of a html table Java

I am still learning xpath and I am trying to skip the first row of a table because the first row has no values. I am not having success i searched through stack over flow and could not find anyone with a similar issue. My code is below:

int reqIndex = 0;

        do {

        List<WebElement> payDates = driver.findElements(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')]/td[contains(@id,'_cell_4')/span]"));
        System.out.println(payDates);

                for(WebElement pd:payDates) {                           
                LocalDate localDate = LocalDate.now();
                java.util.Date d = new SimpleDateFormat("yyyy-MM-dd").parse(localDate.toString());

                  String str = pd.getText();

                  if ( str >= (d) ){ // still figuring this out
                    driver.findElement(By.xpath( "//tr[@id='changeStartWeekGrid_row_'" + reqIndex +"])/TBODY[@id='changeStartWeekGrid_rows_tbody']/TR[7]/TD[1]/DIV[1]/DIV[1]/DIV[1]")).click();
                    break;
                    }else{
                         reqIndex++;
                        }

                        }
                    }while(reqIndex < 7 ); /// do this 7 times

                Thread.sleep(10000);

This is the part i am trouble shooting right now

List<WebElement> payDates = driver.findElements(By.xpath("//tr[starts-with(@id,'changeStartWeekGrid_row_')]/td[contains(@id,'_cell_4')/span]"));
                    System.out.println(payDates);
                    Thread.sleep(10000);

The xpath works the problem is that it is selecting the first row and it has no values row zero does so it needs to skip the first row and go to row zero. when i run the code i get this message:

( //tr[starts-with(@id,'changeStartWeekGrid_row_')]/td[contains(@id,'_cell_4')/span])
ilter expression must evaluate to nodeset.

the row highlighted is the row i am trying to skip enter image description here

cell 4 image

enter image description here

-----radio button html code below

<div id="changeStartWeekGrid.store.rows[5].cells[0]_widget" tabindex="0" class="revitRadioButton dijitRadio" onfocus="var registry = require('dijit/registry'); registry.byId('changeStartWeekGrid').changeActiveCell('changeStartWeekGrid_row_5_cell_0', event);" onblur="var registry = require('dijit/registry'); registry.byId('changeStartWeekGrid').blurActiveCell('changeStartWeekGrid.store.rows[5]', 'changeStartWeekGrid.store.rows[5].cells[0]');"><div class="revitRadioButtonIcon"></div></div>

---radio button picture

enter image description here

Upvotes: 0

Views: 1156

Answers (2)

Alexey Dolgopolov
Alexey Dolgopolov

Reputation: 700

You may also use

//tr[starts-with(@id,'changeStartWeekGrid_row_') and not(starts-with(@id, 'changeStartWeekGrid_row_column'))]/td[5]/span

Upvotes: 1

Andersson
Andersson

Reputation: 52675

Try to use XPath

//table[@id='changeStartWeekGrid_rows_table']//tr[preceding-sibling::tr]

to select all tr nodes except the firts one

You can also use position() as below:

//table[@id='changeStartWeekGrid_rows_table']//tr[position()>1]

Note that in XPath indexation starts from 1 and so [position()>1] predicate means return all sibling nodes skiping the first one

Upvotes: 2

Related Questions