代码之家  ›  专栏  ›  技术社区  ›  Jonas Byström

硒:如何找到特定含量的DIV?

  •  6
  • Jonas Byström  · 技术社区  · 15 年前

    我需要找到一个 <div> 具有一定的内容和 click 它来自硒,因此:

    <tr>
      <td>clickAndWait</td>
      <td>//div[@class='gwt-Label' ***WITH CONTENT='Logout'***]</td>
      <td>5000</td>
    </tr>
    

    有什么办法吗?我不想使用绝对XPath。

    3 回复  |  直到 15 年前
        1
  •  7
  •   krosenvold    15 年前

    试试这个:

     //div[@class='gwt-Label' and contains(., 'Logout')]
    
        2
  •  8
  •   Dave Hunt    15 年前

    您还可以使用CSS定位器:

    <div class="gwt-Label">This FindMe DIV</div>
    

    可通过以下方式定位:

    css=.gwt-Label:contains('FindMe')
    
        3
  •  1
  •   edA-qa mort-ora-y    15 年前

    也许你的xpath并没有完全按照你的想法去做。您可能需要使用string()函数将块中的所有文本连接起来。

    例如,在测试计划(使用Selenium作为后端)中,您可以这样做:

    Click //div[@class='gwt-Label'][contains(string(),'Logout')]
    

    注意字符串()的用法