硒中的下拉选择

时间:2015-07-02 04:13:08

标签: java selenium selenium-webdriver

以下是HTML代码:

select 'icici' bank, 1220 acnum, '09876' ac_ser, 'mh111' state, 'ngp11' city
into #a
union
select 'axis' bank, 4561 acnum, '5786' ac_ser, 'ap' state, 'hyd' city

SELECT ColName, ColValue
FROM
(SELECT bank,  ac_Ser, [state], city
FROM #a) t
UNPIVOT
(ColValue for ColName in (bank,  ac_Ser, [state], city)
) AS val

我遇到了下拉选项的一些问题。我尝试了以下但是它无法正常工作

 <div class="dropdown-datepicker ng-scope" ng-class="{invalid : !o[typeOfDate].valid && formData[typeOfDate], valid : o[typeOfDate].valid}" label-since-month="Seit Monat" label-since-year="Seit Jahr" month-placeholder="Monat" year-placeholder="Jahr" label-datepicker=" seit" date="employedSince" tooltip="Bitte geben Sie hier den Monat und das Jahr an, seit dem Sie in dem Unternehmen beschäftigt sind" set-tabindex="0" r-dropdown-datepicker="">

 <p class="dropdown-date-label bold italic ng-binding"> seit</p>
 <div class="custom-select white month"> 

 <span class="chevron-thin-down">-</span> 
   <select class="special-valid ng-pristine ng-valid ng-scope ng-touched" ng-blur="isSlideValid(slider.index)" ng-model="o[typeOfDate].month" name="years" tabindex="0">
        <option class="ng-binding" style="display: none;" selected="" disabled="" value="">Monat</option> 
       <option class="ng-binding ng-scope" ng-selected="o[typeOfDate].month == $index+1" value="1" ng-repeat="m in monthsDrop">Januar</option>
</select>

 <div class="custom-select white year">
  <select class="special-valid ng-pristine ng-untouched ng-valid ng-scope" ng-blur="isSlideValid(slider.index)" ng-model="o[typeOfDate].year" name="years" tabindex="0"> 
        <option class="ng-binding" style="display: none;" selected="" disabled="" value="">Jahr</option>
        <option class="ng-binding ng-scope" ng-selected="o[typeOfDate].year == y" value="2015" ng-repeat="y in yearsDrop">2015</option>
        <option class="ng-binding ng-scope" ng-selected="o[typeOfDate].year == y" value="2014" ng-repeat="y in yearsDrop">2014</option>

  </select>
 </div>
</div>

请帮帮我

3 个答案:

答案 0 :(得分:0)

试试这个:

    WebElement webElement = driver
            .findElement(By
                    .xpath("//select[@class='special-valid ng-pristine ng-valid ng-scope ng-touched']"));

    Select select = new Select(webElement);
    select.selectByVisibleText("Monat");

您也可以使用,

    select.selectByIndex(1);

而不是

    select.selectByVisibleText();

答案 1 :(得分:0)

要选择该选项,您需要先点击下拉菜单。这将使选项显示。另请注意,选项具有名为disabled的属性,无法进行选择。

尝试下面的代码(C#),可以转换为等效的Java代码......

IWebElement element = driver.findElement(By.xpath("(//select[@name='years'])[3]")); // Assuming you have proper indexing.
element.Click();
SelectElement select = new SelectElement(driver.findElement(By.xpath("(//select[@name='years'])[3]")));
select.SelectByText("Januar"); // Monar option diabled.

让我知道这是否有效。

答案 2 :(得分:0)

您可以将cssSelector用于复合类名称。只需在名称的开头添加一个小数点,并用小数点替换所有“空格”。以下是经过测试并处于工作状态。

new Select(driver.findElement(By.cssSelector(".ng-pristine.ng-valid.needsclick.ng-empty.ng-touched"))).selectByVisibleText(reason1);