1

複数のテーブル内に要素を持つ次のセレン CSS コードを省略できません。以下のコードでは、2 つのチェックボックスが表示されます。

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] 入力のように短縮できるオプションはありますか。

どんな助けでも大歓迎です。

ありがとう

4

1 に答える 1

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

また

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

これはPythonにありますが、webelementリクエストを前のwebdriver要素にチェーンできるため、すべてのバインディングで同じ考え方です

于 2012-05-01T04:01:14.403 に答える