2017-01-25 3 views
0

Вот мой XPath:WebDriver игнорируя содержание Xpath после ::

(//td['displaytablecell']/span[text()='Name1']/../preceding-sibling::td[@class='ui-selection-column']/p-dtcheckbox/div/div[1]/input)[1] 

Селен код WebDriver игнорирует все после :: в приведенном выше XPath.

Ниже приведена ошибка, которую я получаю в селене, когда я выше, используя xpath как локатор для идентификации элемента на странице.

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

Ниже WebDriver Java код:

@Test 
     public void test_byxpath(){ 

      WebDriver driver = new ChromeDriver(); 

      driver.get("http://somesite.com"); 

      WebElement element = driver.findElement(By.xpath("(//td[@style='display: table-cell;']/span[text()='Name1']/../preceding-sibling::td[@class='ui-selection-column']/p-dtcheckbox/div/div[2])[1]"));  
       System.out.println("Test7 number of elements: " + elements.size()); 
      element.click(); 
} 

элемент чекбокс, который я пытаюсь проверить, применяя метод .click().

Ниже результат я получаю в 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) 
+0

Вы уверены, что его не опечатка: 'p-dtcheckbox'? Показать код "HTML" для того же – Andersson

+0

@Andersson, p-dtcheckbox не имеет при себе опечатки. Похоже, что webdriver не устраивает: :: присутствует в моем xpath. – Chuchoo

+0

Если есть какой-либо Java-код, пожалуйста, покажите этот код вместе с полной минимальной версией входного HTML-документа. Благодарю. Дополнительная справка: http://stackoverflow.com/help/mcve. –

ответ

1

Ну, если это не может быть work..then попробовать другой: XPath //td[span[text()='Name1']]/preceding-sibling::td[@class='ui-selection-column']//div[contains(@class,'ui-chkbox-box')/]

Смежные вопросы