javascript
  • java
  • html
  • css
  • selenium-webdriver
  • 2017-07-24 39 views -1 likes 
    -1

    我无法选择下拉列表中的选项使用java在selenium中实现css。 我想用id,但每次改变id。在下拉列表中选择选项materialize css在使用java的硒中

    driver.findElement(By.cssSelector("input.select-dropdown.active")).click(); 
    driver.findElement(By.xpath("//ul[@id='select-options-db8c4be0-fa76-9286-bbef-80bde7193503']/li[2]/span")).click(); 
    

    页来源:

    <div class="input-field"> 
        <div class="select-wrapper validate mandatory"> 
         <span class="caret"></span> 
         <input class="select-dropdown active" type="text" value="Organization Type" data-activates="select-options-465e6e55-1802-f0a6-4956-dafb1c063abc" readonly="true" tabindex="5" style="color: rgb(170, 170, 170);"> 
         <ul id="select-options-465e6e55-1802-f0a6-4956-dafb1c063abc" class="dropdown-content select-dropdown active" style="width: 465px; position: absolute; top: 0px; left: 0px; opacity: 1; display: block;"> 
          <li class="selected"> 
           <span class="" data-target="">Organization Type</span> 
          </li> 
          <li class=""> 
           <span class="" data-target="">Provider</span> 
          </li> 
          <li class=""> 
           <span class="" data-target="">Billing Agent</span> 
          </li> 
         </ul> 
         <select id="orgType" class="validate mandatory initialized" tabindex="5" name="orgType"> 
          <option value="">Organization Type</option> 
          <option value="Provider">Provider</option> 
          <option value="Billing Agent">Billing Agent</option> 
         </select> 
        </div> 
    </div> 
    

    回答

    0

    其所有的XPath创作。你可能会试图像

    Xpath=//li[contains(text(),'Provider')] or //div[@class='input-field']/div/ul/li[2]/span or may others also 
    

    这有助于https://www.guru99.com/xpath-selenium.html

    +0

    ** // DIV [@类= '输入场']/DIV/UL /利[2] /跨度**这被正确地选择......谢谢你兄弟 –

    相关问题