Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Java 如何编写定位器并选择下拉值_Java_Selenium - Fatal编程技术网

Java 如何编写定位器并选择下拉值

Java 如何编写定位器并选择下拉值,java,selenium,Java,Selenium,我尝试了以下代码: Select dropdown = new Select(driver.findElement(By.xpath("//a[contains(text(),'--None--')]"))); dropdown.selectByIndex(1); 获取以下错误: 主线程中的异常 org.openqa.selenium.support.ui.unexpectedtagname异常:元素 本应被选中,但已被选中 这是我的完整DOM结构: <div class="compou

我尝试了以下代码:

Select dropdown = new Select(driver.findElement(By.xpath("//a[contains(text(),'--None--')]")));
dropdown.selectByIndex(1);
获取以下错误:

主线程中的异常 org.openqa.selenium.support.ui.unexpectedtagname异常:元素 本应被选中,但已被选中

这是我的完整DOM结构:

<div class="compoundTLRadius compoundTRRadius compoundBorderBottom form-element__row uiMenu" data-aura-rendered-by="2600:0" data-aura-class="uiMenu">
   <div id="2574:0" data-aura-rendered-by="2581:0" class="uiPopupTrigger" data-aura-class="uiPopupTrigger" data-interactive-uid="19">
      <div data-aura-rendered-by="2583:0"><div data-aura-rendered-by="2576:0">
       <a aria-required="false" class="select" aria-disabled="false" aria-haspopup="true" tabindex="0" role="button" aria-label="Salutation" title="" href="javascript:void(0);" data-aura-rendered-by="2577:0" data-interactive-lib-uid="45">--None--</a>
       </div>
   </div>
</div>
<div class="select-options popupTargetContainer uiPopupTarget uiMenuList uiMenuList--default uiMenuList--left uiMenuList--short" data-aura-rendered-by="2595:0" data-aura-class="uiPopupTarget uiMenuList uiMenuList--default uiMenuList--left uiMenuList--short" aria-labelledby="2574:0"><div class="select-options" role="menu" data-aura-rendered-by="2589:0"><!--render facet: 2590:0-->
<ul class="scrollable" role="presentation" data-aura-rendered-by="2591:0" data- scoped-scroll="true"><!--render facet: 2592:0--></ul>
</div></div></div>

我需要用于定位下拉图标的代码,并从中选择第一个值。

我没有看到下拉列表我不明白一件事-首先没有下拉列表,第二件事是,即使您定位的元素只包含-无-而不是您选择的索引1,索引怎么可能是1?它似乎不是下拉列表。必须使用“单击”而不是“选择”来单击一个选定图元class@metar首先,我想找到下拉图标。我想从下拉列表中选择Mr.值。请建议任何其他度量。@abhishek index1具有Mr.from下拉列表值。首先找到那个下拉图标。上面的代码我试过了。请给我其他的尺寸。