Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用selenium从C中的角度下拉列表中选择值_C#_Angular_Selenium Webdriver - Fatal编程技术网

C# 如何使用selenium从C中的角度下拉列表中选择值

C# 如何使用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"

我正在尝试单击角度下拉列表中的值。当我点击下拉箭头时,有一个选项可用于“建立主要联系人”,我想使用Selenium WebDriver和C单击该选项

我试过以下方法

.SendKeysKeys.arrow向下

我还尝试通过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>
这对我有用

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选择器。下拉选项:第一个孩子