【问题标题】:Need help to get the Selenium cssSelector for the following td attribute to extract the title text需要帮助来获取以下 td 属性的 Selenium cssSelector 以提取标题文本
【发布时间】:2013-12-10 23:58:55
【问题描述】:

需要帮助来获取以下 td 属性的 Selenium cssSelector 以提取“Nothing here”的标题文本

    <table id="myTable">
  <thead>
  <tbody data-bind="foreach: data">
    <tr>
        <td data-bind="attr: { title: $root.tooltipText($data) }" title="Nothing here">
            <i class="colNotes fa hasNoNotes fa-comments-o" data-bind="click: function () { $root.noteClicked($data) }, css: $root.notesCssStyling($data)">
            <span class="colNotesText" data-bind="text: NumberOfNotes">0</span>
            </i>
        </td><br/>
    </tr>
    <tr>
        <td data-bind="attr: { title: $root.tooltipText($data) }" title="Nothing here">
            <i class="colNotes fa hasNoNotes fa-comments-o" data-bind="click: function () { $root.noteClicked($data) }, css: $root.notesCssStyling($data)">
            <span class="colNotesText" data-bind="text: NumberOfNotes">0</span>
            </i>
        </td>
    </tr>
   <tbody>
</table>

我尝试了以下没有运气

driver.findElement(By.cssSelector("#myTable tr:nth-child(1) td[data-bind^='attr: {title']")).getAttribute("title");

【问题讨论】:

    标签: selenium-webdriver css-selectors


    【解决方案1】:

    编辑:假设您只想获取表中的第一个 td,这将起作用:

    driver.findElement(By.cssSelector("#myTable td")).getAttribute("title");
    

    【讨论】:

    • 谢谢。我已经从表格开始添加了整个 html,并添加了 2 个表格行和数据/标题,我需要帮助来提取它。
    • @user2250482 更新了我的答案。
    【解决方案2】:

    感谢所有帮助。这是获得标题的最终工作代码。

    driver.findElement(By.cssSelector("#myTable td:nth-child(1)")).getAttribute("title"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-02
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多