【问题标题】:unable to get webElement无法获取 webElement
【发布时间】:2017-01-23 12:39:26
【问题描述】:

我正在尝试将值发送到表格排序器过滤器,然后选中该值的复选框。

但无法获取 webElement。

HTML:有 4 个过滤框,需要向索引为 1 的过滤框发送值。

<tr class="tablesorter-filter-row tablesorter-ignoreRow" role="row">
<td data-column="0">
<td data-column="1">
<input class="tablesorter-filter" placeholder="" data-column="1" data-lastsearchtime="1485173126687" type="search"/>
</td>
<td data-column="2">
<td data-column="3">
<td data-column="4">
</tr>
</thead>

需要将值发送到给定的文本框 screenshot

【问题讨论】:

  • 显示stacktrace 或错误。

标签: java selenium selenium-webdriver automation


【解决方案1】:

你可以试试:

    //Get a list of all the checkboxes
    List<WebElement> listOfElements = webDriver.findElements(By.xpath("//tr[@class='tablesorter-filter-row tablesorter-ignoreRow']/td"));
    //click on the text box of index 1.
    listOfElements.get(1).click();

【讨论】:

  • org.openqa.selenium.InvalidSelectorException:无效选择器:无法使用 xpath 表达式 //tr[@class'tablesorter-filter-row tablesorter-ignoreRow']td/ 定位元素,因为以下错误:SyntaxError: 无法对“文档”执行“评估”:字符串 '//tr[@class'tablesorter-filter-row tablesorter-ignoreRow']td/' 不是有效的 XPath 表达式。
  • 我更新了我的答案,你能再试一次吗?没注意到我在应该是/td的地方写了td/
  • 问题仍然存在。 ]/td 因为以下错误: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//tr[@class'tablesorter-filter-row tablesorter-ignoreRow']/td' is not a valid XPath表达。
  • 你能再试一次吗?
  • 它通过给出明确的等待来工作。非常感谢
猜你喜欢
  • 1970-01-01
  • 2015-10-18
  • 1970-01-01
  • 2017-11-15
  • 2018-08-02
  • 2016-02-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多