猿问

如何通过 Selenium 和 Java 在 <md-select>

我正在尝试自动化具有类型下拉列表的应用程序。我已经尝试了所有可能的组合,如下所示,但无法从下拉列表中选择一个元素。

driver.findElement(By.xpath("//span[@aria-label=\"Phone to call with\"]"));

我无法通过 ID 找到 xpath,因为它会随着重新加载而不断变化。

下面是html代码。我将如何实现相同的目标?


<md-select ng-model="ctrl.selectedLinkedPhone" class="ng-pristine ng-valid ng-empty ng-touched" tabindex="0" aria-disabled="false" role="listbox" aria-expanded="false" aria-multiselectable="false" id="select_26" aria-invalid="false" aria-label="

        Phone to call with

      " style=""><md-select-value class="md-select-value md-select-placeholder" id="select_value_label_25"><span>

        Phone to call with

      </span><span class="md-select-icon" aria-hidden="true"></span></md-select-value><div class="md-select-menu-container" aria-hidden="true" role="presentation" id="select_container_27"><md-select-menu role="presentation" class="_md"><md-content class="_md">

        <!----><md-option ng-disabled="!ctrl.isLinkedPhoneCurrentlyVerified(linkedPhone)" ng-repeat="linkedPhone in ctrl.getLinkedPhones()" ng-value="linkedPhone" tabindex="0" class="md-ink-ripple" role="option" aria-selected="false" id="select_option_29" aria-checked="true" aria-disabled="false" value="[object Object]" style=""><div class="md-text">

          Phone 1

        </div></md-option><!----><md-option ng-disabled="!ctrl.isLinkedPhoneCurrentlyVerified(linkedPhone)" ng-repeat="linkedPhone in ctrl.getLinkedPhones()" ng-value="linkedPhone" tabindex="0" class="md-ink-ripple" role="option" aria-selected="false" id="select_option_30" aria-checked="true" aria-disabled="false" value="[object Object]" style=""><div class="md-text">




德玛西亚99
浏览 166回答 3
3回答

紫衣仙女

要单击带有文本的元素作为电话与您通话,您需要诱导WebDriverWait以使所需元素可点击,您可以使用以下解决方案:new&nbsp;WebDriverWait(driver,&nbsp;20).until(ExpectedConditions.elementToBeClickable(By.xpath("//md-select[@class='ng-pristine&nbsp;ng-valid&nbsp;ng-empty&nbsp;ng-touched']/md-select-value[@class='md-select-value&nbsp;md-select-placeholder'&nbsp;and&nbsp;starts-with(@id,'select_value_label_')]//span[contains(.,'Phone&nbsp;to&nbsp;call&nbsp;with')]"))).click();

慕侠2389804

如果该下拉列表是由 div 标签开发的,那么我们必须使用 Action Class 方法来自动化它。如果可能,您可以发送该页面 Url,我将发送解决方案。
随时随地看视频慕课网APP

相关分类

Java
我要回答