简体   繁体   English

跳过HTML表格Java的第一行

[英]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. 我仍在学习xpath,并且试图跳过表的第一行,因为第一行没有值。 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. xpath起作用的问题是它正在选择第一行,并且它没有任何值,行0会这样做,因此它需要跳过第一行并转到行0。 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 突出显示的行是我要跳过的行 在此处输入图片说明

cell 4 image 单元格4图片

在此处输入图片说明

-----radio button html code below -----单选按钮html代码如下

<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 ---单选按钮图片

在此处输入图片说明

Try to use XPath 尝试使用XPath

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

to select all tr nodes except the firts one 选择除第一个以外的所有tr节点

You can also use position() as below: 您还可以如下使用position()

//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 请注意,在XPath中,索引从1开始,因此[position()>1]谓词意味着返回所有跳过第一个节点的同级节点。

您也可以使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM