Java WebDriver忽略以下内容后的Xpath内容:
这是我的xpath:Java WebDriver忽略以下内容后的Xpath内容:,java,selenium,xpath,selenium-webdriver,Java,Selenium,Xpath,Selenium Webdriver,这是我的xpath: (//td['displaytablecell']/span[text()='Name1']/../preceding-sibling::td[@class='ui-selection-column']/p-dtcheckbox/div/div[1]/input)[1] Selenium WebDriver代码忽略了上述xpath中::之后的所有内容 下面是当我在上面使用xpath作为定位器来标识页面中的元素时,在selenium中遇到的错误 Exception occu
(//td['displaytablecell']/span[text()='Name1']/../preceding-sibling::td[@class='ui-selection-column']/p-dtcheckbox/div/div[1]/input)[1]
Selenium WebDriver代码忽略了上述xpath中::之后的所有内容
下面是当我在上面使用xpath作为定位器来标识页面中的元素时,在selenium中遇到的错误
Exception occured: org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression (//td['displaytablecell']/span[text()='Name1']/../preceding-sibling because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '(//td['displaytablecell']/span[text()='Name1']/../preceding-sibling' is not a valid XPath expression.
关于如何让webdriver使用上面的整个xpath,有什么想法或建议吗
下面是HTML
代码:
<td class="ui-selection-column" ng-reflect-ng-class="[object Object]" ng-reflect-ng-style="[object Object]" style="width: 38px; display: table-cell;">
<!--template bindings={ "ng-reflect-ng-if": "true" }-->
<span class="ui-column-title"/>
<p-dtcheckbox>
<div class="ui-chkbox ui-widget">
<div class="ui-helper-hidden-accessible">
<input type="checkbox"/>
</div>
<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default" ng-reflect-klass="ui-chkbox-box ui-widget ui-corner-all ui-state-default" ng-reflect-ng-class="[object Object]">
</div>
</p-dtcheckbox>
</td>
<!--template bindings={ "ng-reflect-ng-if": "true" }-->
<td ng-reflect-ng-class="[object Object]" style="display: table-cell;">
元素是我试图通过应用方法来检查的复选框。单击()
下面是我在Eclipse中得到的结果:
Retrieving object of type 'xpath' and value '(//td[@style='display' from the object map
2017-01-25 16:52:09 -- INFO automation.utilities.EventHandlerListener:102 - Trying to Find By.xpath: (//td[@style='display.
2017-01-25 16:52:10 -- INFO automation.utilities.EventHandlerListener:98 - Exception occured: org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression (//td[@style='display because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '(//td[@style='display' is not a valid XPath expression.
(Session info: chrome=53.0.2785.143)
如果这不起作用,那么可以尝试另一种xpath:
//td[span[text()='Name1']]/previous sibling::td[@class='ui-selection-column']///div[contains(@class,'ui-chkbox-box')//]
您确定这不是打字错误:p-dtcheckbox
?显示应用程序的HTML
代码same@Andersson,p-dtcheckbox没有任何打字错误。看起来webdriver对xpath中的::不太满意。如果有任何Java代码,请在此处显示该代码,以及输入HTML文档的完整、最低版本。谢谢更多帮助:。我不知道问题的答案,但我非常确定XPath表达式是有效的。@Chucho它不会解决您当前的问题,但您正在尝试单击列表-您应该使用findElement
而不是findElements
Retrieving object of type 'xpath' and value '(//td[@style='display' from the object map
2017-01-25 16:52:09 -- INFO automation.utilities.EventHandlerListener:102 - Trying to Find By.xpath: (//td[@style='display.
2017-01-25 16:52:10 -- INFO automation.utilities.EventHandlerListener:98 - Exception occured: org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression (//td[@style='display because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '(//td[@style='display' is not a valid XPath expression.
(Session info: chrome=53.0.2785.143)