0

My code is like this..

<ul class="sb_dropdown" style="display: none;">
 <li id="sb_up_arrow" class="uiebatesca"/>
  <li>
  <label data-search-for="all">
    <strong>All</strong>
  </label>
 </li>
 <li style="background-color: transparent;">
   <label data-search-for="Automotive">Stores</label>
  </li>
  <li>
   <label data-search-for="Beauty">Deals</label>
  </li>
 </ul>
</form>

Now i want to select Stores by using webdriver with java.
I tried by using:

List<WebElement> elementsList = driver.findElements(By.xpath("//form[@id='ui_element']/ul/li"));
Select ddvalues=new Select(elementsList.get(1)); 
ddvalues.selectByIndex(1);

But this is not working...

Is there any alternate ways to select this Stores.

I tried to focus move to the "Stores" label, with this code...

Actions builder = new Actions(driver);      
builder.moveToElement(elementsList.get(i)).perform();
elementsList.get(i).click();

but this is also not working...

4

1 回答 1

0

我假设通过“选择”,您需要单击“商店”标签。正如其他人指出的那样,使用 a 选择一个项目是new Select()行不通的,因为它期望元素是一个元素。

您可以使用以下方法“选择”“商店”标签:

IWebElement element = driver.findElement(By.xpath("//label[text()='Stores'])"));
element.click();
于 2013-08-13T17:49:05.713 回答