[英]How to select a value from Devextreme dropdown with Selenium C#
[英]How to select a value from an angular dropdown in C# with selenium
我正在嘗試從角度下拉列表中單擊一個值。 當我單擊下拉箭頭時,我想使用Selenium WebDriver和C#單擊的“成為主要聯系人”選項變為可用
我嘗試了以下
.SendKeys(Keys.ArrowDown)
我也嘗試通過XPath定位該元素,但由於它是動態的,因此也不起作用。
這是HTML
<section>
<div class="entry-box">
<input class="inv-input" [ngModel]="value?.ItemValue" (ngModelChange)="updatePhoneNumber($event)"/>
<div class="caret-container" (click)="toggleDropDown()">
<span *ngIf="value?.IsPrimary">{{'contactDetailsTab.selectedPrimaryLabel' | translate}}</span>
<img class="select-icon" src="/assets/app/caret-dark.svg">
</div>
</div>
<ng-container *ngIf="showDropDown">
<div class="dropdown-container">
<ul #dropDown tabIndex="-1" class="dropdown" (blur)="onBlur()">
<li *ngIf="!value?.IsPrimary" (mousedown)="setPrimary(true)">{{'contactDetailsTab.makePrimaryContact' | translate}}</li>
<li *ngIf="value?.IsPrimary" (mousedown)="setPrimary(false)">{{'contactDetailsTab.removePrimaryContact' | translate}}</li>
</ul>
</div>
</ng-container>
</section>
我使用Selenium的SelectElement函數:
new SelectElement(driver.FindElement(By.Xpath("your Xpath here"))).SelectByText("Make Primary Contact");
在這里,您可以獲得有關SelectElement的更多信息。
是處理下拉列表並檢查其中值的最佳方法。 您還可以選擇SelectByIndex或任何更適合您的內容。
這對我有用
driver.FindElement(By.XPath("//li[contains(., 'Make Primary Contact')]"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.