2012-04-03 4 views
1

複数の表の中に要素がある次のセレニウムCSSコードを省略するのに問題があります。以下のコードは私に2つのチェックボックスを与えます。テーブル要素の長い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コードを短縮することができますか?

テーブル[id $ = gridReports]> tbody> tr:nth-​​of-type(i)とそれに続くspan [id $ = reportCheckBox]のように短縮できるオプションはありますか?

ご協力いただければ幸いです。

おかげ

答えて

1

あなたは宇宙狭くすることで、それを短縮することができ

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") 

ORチェーンにwebelement要求をすることができますようにすべてのバインディングでのpythonが、同じ考え方であります

els = driver.find_elements_by_css_selector("span[id$=reportCheckBox] input") 
for el in els: 
    el.click() 

前のwebdriver要素

関連する問題