【发布时间】:2012-05-01 12:01:14
【问题描述】:
我在缩写以下 selenium CSS 代码时遇到问题,该代码在多个表中包含元素。下面的代码给了我两个复选框。
table[id$=gridReports]>tbody>tr:nth-of-type(2)>td:nth-of-type(2)>table[id$=panelReportInformation]>tbody>tr:nth-of-type(2)>td>table[id$=panelReportContent]>tbody>tr:nth-of-type(2)>span[id$=reportCheckBox] input
我无法使用此代码,因为还有另一个具有相同跨度和复选框的表。唯一的区别是它在不同的行中。因此,如果我将代码放入另一个复选框,它将如下所示。
table[id$=gridReports]>tbody>tr:nth-of-type(3)>td:nth-of-type(2)>table[id$=panelReportInformation]>tbody>tr:nth-of-type(2)>td>table[id$=panelReportContent]>tbody>tr:nth-of-type(2)>span[id$=reportCheckBox] input
因此,唯一的区别是每个表的类型为 nth-of-type(i)。那么如何缩短css代码呢?
是否有任何我可以缩短的选项,例如 table[id$=gridReports]>tbody>tr:nth-of-type(i) 后跟 span[id$=reportCheckBox] 输入。
任何帮助将不胜感激。
谢谢
【问题讨论】:
标签: css css-selectors selenium-rc selenium-chromedriver