Visual studio 我无法找到我的应用程序的位置下拉列表(自动完成)。下面是给出的代码

Visual studio 我无法找到我的应用程序的位置下拉列表(自动完成)。下面是给出的代码,visual-studio,selenium,selenium-webdriver,Visual Studio,Selenium,Selenium Webdriver,我想从下拉列表中获取位置,它是自动完成的下拉列表,并在下拉列表中设置位置loc 2,但我无法这样做。使用SeleniumWeb驱动程序 <div class="col-12 col-md-4 col-lg-3"> <div class="form-group mb-lg-0"> <select class="select-site custom-select custom-select-lg select2-hidden-accessible

我想从下拉列表中获取位置,它是自动完成的下拉列表,并在下拉列表中设置位置
loc 2
,但我无法这样做。使用SeleniumWeb驱动程序

<div class="col-12 col-md-4 col-lg-3">
    <div class="form-group mb-lg-0">
        <select class="select-site custom-select custom-select-lg select2-hidden-accessible" data-select2-id="1" tabindex="-1" aria-hidden="true">
            <option value="0" selected="selected" data-select2-id="14">-- All Sites --</option>
            <option value="35" data-select2-id="15">Loc 1</option>
            <option value="19" data-select2-id="16">Loc 2</option>
        </select><span class="select2 select2-container select2-container--default select2-container--below select2-container--open" dir="ltr" data-select2-id="2" style="width: 250.406px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-disabled="false" aria-labelledby="select2-k9e1-container" aria-owns="select2-k9e1-results" aria-activedescendant="select2-k9e1-result-bhnd-13"><span class="select2-selection__rendered" id="select2-k9e1-container" role="textbox" aria-readonly="true" title="abc">abc</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span>
        </span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
    </div>
</div>
<span class="select2 select2-container select2-container--default select2-container--below select2-container--open" dir="ltr" data-select2-id="2" style="width: 250.406px;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-disabled="false" aria-labelledby="select2-k9e1-container" aria-owns="select2-k9e1-results" aria-activedescendant="select2-k9e1-result-bhnd-13"><span class="select2-selection__rendered" id="select2-k9e1-container" role="textbox" aria-readonly="true" title="abc">abc</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span>
</span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
<span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-k9e1-container"><span class="select2-selection__rendered" id="select2-k9e1-container" role="textbox" aria-readonly="true" title="abc">abc</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span>
<span class="select2-selection__rendered" id="select2-k9e1-container" role="textbox" aria-readonly="true" title="abc">abc</span>
<span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
<b role="presentation"></b>

--所有站点--
Loc 1
Loc 2
abc
abc
abc
abc
需要自动化位置下拉列表。

尝试以下操作:

WebElement locationDropdown = driver.findElement(By.cssSelector("select[data-select2-id='1']"));
Select select = new Select(locationDropdown);
select.selectByVisibleText("Loc 2");

请添加您的尝试也