C# 如何使用selenium从C中的角度下拉列表中选择值
我正在尝试单击角度下拉列表中的值。当我点击下拉箭头时,有一个选项可用于“建立主要联系人”,我想使用Selenium WebDriver和C单击该选项 我试过以下方法 .SendKeysKeys.arrow向下 我还尝试通过XPath定位元素,但由于它是动态的,这也不起作用 这是HTMLC# 如何使用selenium从C中的角度下拉列表中选择值,c#,angular,selenium-webdriver,C#,Angular,Selenium Webdriver,我正在尝试单击角度下拉列表中的值。当我点击下拉箭头时,有一个选项可用于“建立主要联系人”,我想使用Selenium WebDriver和C单击该选项 我试过以下方法 .SendKeysKeys.arrow向下 我还尝试通过XPath定位元素,但由于它是动态的,这也不起作用 这是HTML <section> <div class="entry-box"> <input class="inv-input" [ngModel]="value?.ItemValue"
<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>
这对我有用
driver.FindElement(By.XPath("//li[contains(., 'Make Primary Contact')]"));
这对我有用
driver.FindElement(By.XPath("//li[contains(., 'Make Primary Contact')]"));
我使用Selenium的SelectElement功能:
new SelectElement(driver.FindElement(By.Xpath("your Xpath here"))).SelectByText("Make Primary Contact");
是处理下拉列表并检查其中值的最佳方法。您还可以选择索引或任何更适合您的选项。我使用Selenium的SelectElement功能:
new SelectElement(driver.FindElement(By.Xpath("your Xpath here"))).SelectByText("Make Primary Contact");
是处理下拉列表并检查其中值的最佳方法。您还可以选择ByIndex或任何更适合您的选项。由于它是自定义下拉列表,您可以提供处理箭头键使用的代码吗?可以使用css选择器吗。下拉选项:第一个孩子因为它是自定义的下拉菜单,你能提供处理箭头键使用的代码吗?可能通过使用css选择器。下拉选项:第一个孩子