需要脚本来选择下拉列表中的值

时间:2017-04-25 09:57:15

标签: selenium selenium-webdriver

我想首先选择类别,然后在下拉列表中选择HONDA值  下面的代码是选择类别

<div>
<ul class="nav nav-tabs customtabview" role="tablist">
<div class="tab-content customtabcontainer">
<div id="general" class="tab-pane active">
<form class="form-horizontal form-validation row-border ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-valid-min ng-valid-max ng-valid-pattern ng-valid-minlength" angular-validator-submit="equipmentsavegeneral()" name="equipmentsave" novalidate="" angular-validator="">
<div class="form-group">
<label class="col-sm-4 control-label">
Category
<span class="mandatory">*</span>
</label>
<div class="col-sm-6">
<oi-select class="ng-pristine ng-valid ng-isolate-scope ng-touched" oi-options="item.id as item.category_name for item in dropdown.categoryname" ng-model="formdata.category" placeholder="Select Category" ng-disabled="formdata.id" ng-change="checksubcategory(formdata.category)">
<div class="select-search">
<ul class="select-search-list">
<li class="select-search-list-item select-search-list-item_input" ng-class="{'select-search-list-item_hide': inputHide}">
<input class="ng-pristine ng-valid ng-touched" autocomplete="off" ng-model="query" ng-keyup="keyUp($event)" ng-keydown="keyDown($event)" placeholder="Select Category">
</li>
<li class="select-search-list-item select-search-list-item_loader ng-hide" ng-show="showLoader"></li>
</ul>
</div>
<div class="select-dropdown ng-hide" ng-show="isOpen"></div>
</oi-select>
<input class="ng-pristine ng-untouched ng-invalid ng-invalid-required" style=" display: none;" data-ng-model="formdata.category" name="selectcat" required="" required-message="'Please select category'" type="text">
</div>
</div>

Below code is to select the value 

    <div class="select-dropdown" ng-show="isOpen">
<ul class="select-dropdown-optgroup ng-scope" ng-if="isOpen" ng-repeat="(group, options) in groups">
<li class="select-dropdown-optgroup-option ng-binding ng-scope ungroup" ng-init="isDisabled = getDisableWhen(option)" ng-repeat="option in options" ng-class="{'active': selectorPosition === groupPos[group] + $index, 'disabled': isDisabled, 'ungroup': !group}" ng-click="isDisabled || addItem(option)" ng-mouseenter="setSelection(groupPos[group] + $index)" ng-bind-html="getDropdownLabel(option)">Bike details</li>
<li class="select-dropdown-optgroup-option ng-binding ng-scope ungroup" ng-init="isDisabled = getDisableWhen(option)" ng-repeat="option in options" ng-class="{'active': selectorPosition === groupPos[group] + $index, 'disabled': isDisabled, 'ungroup': !group}" ng-click="isDisabled || addItem(option)" ng-mouseenter="setSelection(groupPos[group] + $index)" ng-bind-html="getDropdownLabel(option)">Test</li>
<li class="select-dropdown-optgroup-option ng-binding ng-scope ungroup" ng-init="isDisabled = getDisableWhen(option)" ng-repeat="option in options" ng-class="{'active': selectorPosition === groupPos[group] + $index, 'disabled': isDisabled, 'ungroup': !group}" ng-click="isDisabled || addItem(option)" ng-mouseenter="setSelection(groupPos[group] + $index)" ng-bind-html="getDropdownLabel(option)">b</li>
<li class="select-dropdown-optgroup-option ng-binding ng-scope ungroup" ng-init="isDisabled = getDisableWhen(option)" ng-repeat="option in options" ng-class="{'active': selectorPosition === groupPos[group] + $index, 'disabled': isDisabled, 'ungroup': !group}" ng-click="isDisabled || addItem(option)" ng-mouseenter="setSelection(groupPos[group] + $index)" ng-bind-html="getDropdownLabel(option)">LoadOne</li>
<li class="select-dropdown-optgroup-option ng-binding ng-scope ungroup active" ng-init="isDisabled = getDisableWhen(option)" ng-repeat="option in options" ng-class="{'active': selectorPosition === groupPos[group] + $index, 'disabled': isDisabled, 'ungroup': !group}" ng-click="isDisabled || addItem(option)" ng-mouseenter="setSelection(groupPos[group] + $index)" ng-bind-html="getDropdownLabel(option)">HONDA</li>
</ul>
</div>
</oi-select>

需要脚本来选择这个我已经使用了xpaths它没有工作获取元素

1 个答案:

答案 0 :(得分:0)

在python中根据可见文本选择项目uc在代码下面使用。

from selenium.webdriver.support.ui import Select

element_obj = element_obj = driver.find_element_by_id('element_id')
select = Select(element_obj)
select.select_by_visible_text('HONDA')

获取所有可用下拉选项的列表。

element_obj = element_obj = driver.find_element_by_id('element_id')            
select = Select(element_obj)
return [o.text for o in select.options]

我不确定,这是您的要求,但解决方案是基于我对您的问题的理解