2014-11-01 74 views
1

如何在硒的webdriver如何选择“Span类型下拉列表”中硒值的webdriver

我能够通过使用XPath点击下拉菜单,但不能选择选择“跨类型下拉”的价值下拉列表中的值。我的XPath点击下拉菜单是: driver.findElement(By.xpath(“.//*[@ id ='minexpButton']/span”))。click();

当我使用硒上面的代码,下拉展开,但我无法从下拉列表中选择值

我的HTML代码如下:

<span id="minexpButton" class="yui-button yui-menu-button yui-button-active yui-menu-button-active" style="background-color: rgb(255, 255, 255); display: -moz-inline-box;"> 

    <div id="minexpSelectionMenu" class="yui-module yui-overlay yui-button-menu yui-menu-button-menu" style="z-index: 1003; visibility: visible; left: 367.683px; top: 1050.6px;"> 

    <div class="bd"> 
    <div class="selectionMenu"> 
    <div class="ulDiv" style="overflow: auto; width: 64px; height: 210px;"> 
    <div class="liDiv selected"> 

    <a class="txt_black heading_4" href="#" tabindex="-1" target="_self">- Min -</a> 
    </div> 

    <div class="liDiv"> 
    <a class="txt_black heading_4" href="#" tabindex="-1" target="_self">0</a> 
    </div> 

    <div class="liDiv"> 
    <a class="txt_black heading_4" href="#" tabindex="-1" target="_self">1</a> 
    </div> 

请帮我从下拉列表中选择值 谢谢, Nagaraju

+0

。恳求se从下拉列表中选择代码并且.//*[@id='minexpButton']/span - >我没有看到一个span标签,它是id ='minexpButton'的标签的子代 – 2014-11-01 14:43:21

回答

0

您可以使用下面的函数从您的下拉
的BEL选择值流功能会从下拉列表中选择0值,可以参数以下行 (temp.equals(“0”),并通过您要选择

List<WebElement> element = driver.findElements(By.cssSelector(".txt_black.heading_4")); 
    for (int i = 0; i < element.size(); i++) { 
     String temp = element.get(i).getText(); 
     if (temp.equals("0")) { 
      element.get(i).click();    
      break; 
     } 
    } 
0

我相信应用你的价值自动化正在使用YUI库。

YUI库中的注意点击包含'yui-menu-button'的类的每个元素将显示下拉菜单项。这些菜单项被封装在包含类“yui-menu-button-menu”的DIV元素中。

您的案例中的应用程序的体系结构正在实施后缀。我相信并纠正我,如果我错了,页面上所有的下拉列表中的ID的格式为:

[dropdownName]按钮 & [dropdownName] SelectionMenu

如。

<span id="countryButton" class="..."> 
</span> 
.... 
<div id="countrySelectionMenu" class=""> 
.... 
</div> 

所以下拉列表的实际名称/编号是'国家'。在上述情况下,它是'minexp'。 (我认为最低的体验,因此DropdownID是'minexp',而不是'minexpButton'或'minexpSelectionMenu'。它可能与您的应用程序中的其他元素类似地应用。请对应用程序进行架构审查,以更好地理解元素ID 。和YUI库

这里是你如何从一个YUI SelectMenu(下拉菜单)选择:

// Remember dropdownID is the 'minexp' and not 'minexpButton' or 'minexpSelectionMenu'  
public void selectOption(String dropdownID, String optionText) { 
     // Get the dropdown button 
     WebElement dropdownButton = driver.findElement(By.id(dropdownID & "Button")); 

     // Click on the dropdown button, this will make the selection menu visible 
     dropdownButton.click(); 

     // Get the dropdown selection menu, since it is now visible you can select from it 
     WebElement dropdownMenu = driver.findElement(By.id(dropdownID & "SelectionMenu")); 

     // Verify selection menu is visible 
     if(dropdownMenu.isDisplayed()) { 
      List<WebElement> menuItems = dropdownMenu.findElements(By.tagName("a")); 
      for(WebElement menuItem : menuItems) { 
       if(menuItem.getText().trim().toLowerCase().equalsIgnoreCase(optionText.trim().toLowerCase())) { 
         menuItem.click(); 
         break; 
       } 
      } 
     }   
} 

屡试不爽的YUI Library for Dropdown

我希望这有助于:)

+0

@ nagaraju-gampa它有用吗? – 2014-12-10 11:48:40

相关问题