如何使用Firebug获取网格单元的XPath?

时间:2016-02-02 10:22:22

标签: firefox selenium xpath firebug

我正在使用UI。我的工作是自动化它。我遇到了以下网格。

This is the grid I am working on.

当您点击规则列下的任何单元格时,会出现一个浏览按钮。

After clicking a cell Under Rule column

我应该自动化这种情况。所以,使用Firebug我试图提取该单元格的XPath。 我使用Firebug的检查器找到那个特定的单元格,这样我就可以为它编写XPath,但是我无法找到那个单元格。相反,整个行都会被选中,如下图所示。

Entire row gets highlighted when the cell is hovered using Firebug's inspector tool

Found element after selecting that entire highlighted row

我该如何处理这个问题?

1 个答案:

答案 0 :(得分:0)

下面的代码可能会帮助您验证网格值,

 public void verifyTableValues(String expectedValue
                ) {
            try {
            //List of Fields values which you want to verify
                List<String> expectedValues = Arrays.asList(expectedValue.split("#"));
                // you will get the number of rows in Table Select the xpath to /tr
                String tableRow = driver.findElements(By.xpath(//table row constant));
                int tableRwCnt = getCount(tableRow);
                // you will get the number of Columns in Table Select the xpath to /td
                String tableColumn = driver.findElements(By.xpath(//table Column constant));

                int tableColumnCnt = getCount(tableColumn);

                for (int cnt = 1; cnt <= tableRwCnt; cnt++) {
                    for (int listCount = 1; listCount <= tableColumnCnt; listCount++) {
                        String actualVal = findElement(By.xpath(tableColumn + "[" + cnt + "]/td["
                                + expectedValues.get(listCount) + "]").getText();
                        String expectdVal = expectedValues.get(listCount);
                        Assert.assertEquals("Value from table doent Match", expectdVal, actualVal);
                    }
                }
            } catch (Exception e) {
             // code for exception                

            }
        }


Parameter: expectedValue = test1#test2#test4#test4 (Grid values)