如何从列表中获取值,而不是硒中的下拉列表

<div class="Select form-control undefined Select--single is-searchable has-value"><input name="deal.listdealasset[0].acacode" type="hidden" value="NEWCAR"><div class="Select-control"><span class="Select-multi-value-wrapper" id="react-select-3--value"><div class="Select-value"><span class="Select-value-label" id="react-select-3--value-item" role="option" aria-selected="true">New</span></div><div class="Select-input" 

我正在尝试从下拉列表中选择一个值,但它的html标签不是选择的。我尝试了各种选择但没有工作。


WebElement optionsList = driver.findElement(By.xpath("//span[contains(@class, 'Select-multi-value-wrapper')]"));

List<WebElement> options = optionsList.findElements(By.xpath("//span[contains(@class, 'Select-value-label')]"));

options.get(0).click();

我想从下拉列表中选择新值。[ 在此输入图像描述]


我在执行时遇到错误 - 元素无法滚动到视图中


以下是该页面的HTML代码 -


<div class="Select form-control undefined Select--single is-searchable has-value">

   <input name="deal.listdealasset[0].acacode" type="hidden" value="NEWCAR">

   <div class="Select-control">

      <span class="Select-multi-value-wrapper" id="react-select-3--value">

         <div class="Select-value"><span class="Select-value-label" id="react-select-3--value-item" role="option" aria-selected="true">New</span></div>

         <div class="Select-input" style="display: inline-block;">

            <style>input#undefined::-ms-clear {display: none;}</style>

            <input role="combobox" aria-expanded="false" aria-haspopup="false" aria-activedescendant="react-select-3--value" aria-owns="" style="width: 19px; box-sizing: content-box;" value="" data-rxName="deal.listdealasset[0].acacode">

            <div style="left: 0px; top: 0px; height: 0px; text-transform: none; letter-spacing: normal; overflow: scroll; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-weight: 400; white-space: pre; visibility: hidden; position: absolute;"></div>

         </div>

      </span>

      <span class="Select-arrow-zone"><span class="Select-arrow"></span></span>

   </div>

</div>


小唯快跑啊
浏览 539回答 4
4回答

拉风的咖菲猫

由于你得到的元素错误无法滚动到视图中。您应该尝试使用JavascriptExecutor进行滚动。这种方式允许您水平/垂直((JavaScriptExecutor)driver).executeScript("scroll(0,200)")滚动页面 - 仅垂直滚动200像素2。使元素成为焦点((JavaScriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java