Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何缩短表元素的长Selenium CSS代码?_Css_Css Selectors_Selenium Rc_Selenium Chromedriver - Fatal编程技术网

如何缩短表元素的长Selenium CSS代码?

如何缩短表元素的长Selenium CSS代码?,css,css-selectors,selenium-rc,selenium-chromedriver,Css,Css Selectors,Selenium Rc,Selenium Chromedriver,我在缩写下面的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:

我在缩写下面的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
所以唯一的区别是每个表的类型(i)的第n个。那么如何缩短css代码呢

是否有任何选项可以缩短,如表[id$=gridReports]>tbody>tr:n类型(i),后跟span[id$=reportCheckBox]输入

任何帮助都将不胜感激


谢谢

你可以通过缩小你的宇宙来缩短它

el = driver.find_element_by_css_selector("table[id$=gridReports]>tbody>tr:nth-of-type(3)")
el.find_element_by_css_selector("span[id$=reportCheckBox] input")


这在python中是一样的,但在所有绑定中都是一样的,因为您可以将webelement请求链接到以前的webdriver元素

您可以通过缩小范围来缩短它

el = driver.find_element_by_css_selector("table[id$=gridReports]>tbody>tr:nth-of-type(3)")
el.find_element_by_css_selector("span[id$=reportCheckBox] input")

在python中是这样,但在所有绑定中都是这样,因为您可以将webelement请求链接到以前的webdriver元素