2016-06-02 3 views
0

Из следующего HTML-кода я пытаюсь выбрать с использованием Selenium WebDriver, однако, похоже, я не могу, потому что у элементов есть идентификаторы жидкости. Как я могу найти такие элементы? Я не могу использовать By.className("cs-autocomplete-input"), потому что на веб-странице есть несколько элементов с этим именем класса.Поиск элементов с флюидами xpaths с селеном

<div class="content"> 
    <div id="fluid-id-bhlpjo3p-1026"> 
     <input type="button" class="csc-repeatable-add-bhlpjo3p-1022 cs-repeatable-add" value="+"> 
     <ul class="cs-repeatable"> 
      <li class="csc-repeatable-repeat-bhlpjo3p-1022 clearfix cs-repeatable-repeat show"> 
       <input type="radio" class="csc-repeatable-primary-bhlpjo3p-1022 show cs-repeatable-primary" name="primary-fields.sponsors" value="true"> 
       <input type="text" class="csc-exhibition-sponsor cs-repeatable-content" id="repeat::.csc-exhibition-sponsor" name="repeat::.csc-exhibition-sponsor" style="display: none;"> 
       <input class="cs-autocomplete-input" tabindex=""> 
       <a href="#" class="cs-autocomplete-closebutton" title="Cancel edit, and return this field to the most recent authority value" style="display: none;"></a> 
       <input type="button" value="" class="csc-repeatable-delete-bhlpjo3p-1022 cs-repeatable-delete" disabled=""> 
      </li> 
     </ul> 
    </div> 

Не уверен, что это полезно, но XPath этого DIV является //*[@id="primaryTab"]/div/div[3]/div[1]/div[2]/div[2]/div[1]/div/div[2]

ответ

2

Вы можете попробовать что-то вроде этого:

browser.findElement(By.id("primaryTag")).findElement(By.cssSelector(".cs-autocomplete-input[tabindex='']")) 

Вот CSS в действии.

#someId .my-input[tabindex=''] { 
 
    background: red; 
 
} 
 

 
/* styles for example readability — ignore */ 
 
input { 
 
    display: block; 
 
    margin-bottom: 1em; 
 
    padding: 0.5em 1em; 
 
}
<div id="someId"> 
 
    <input class="my-input" tabindex="3" type="text" value='not me' /> 
 
    <input class="my-input" tabindex="3" type="text" value='not me' /> 
 
    <input class="my-input" tabindex="" type="text" value=' me' /> 
 
    <input class="my-input" tabindex="3" type="text" value='not me' /> 
 
    <input class="my-input" tabindex="" type="text" value='me' /> 
 
</div>

+0

Спасибо так много! Это сработало – ceez

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