1

我尝试select()在我的代码中使用该方法,但 Eclipse 显示错误。是select()Selenium 的内置方法吗?我不明白。

select(driver2.findElement(By.xpath("//*@id='webLossReport.contact.address.state']")),index=i);

Eclipse 说"The method select(WebElement, int) is undefined for the type entry",它给了我一个在这个类中创建方法的选项。

请让我知道其他人如何使用它。我的要求是“根据索引号选择列表值”

更新:按要求发布的代码,

WebElement LSD = driver2.findElement(By.xpath("//select[@id='webLossReport.lossInformation.locationOfLoss.state']"));
List <WebElement> LLS = LossStateDropdown.findElements(By.tagName("option"));

int i= LLS.size();      
select(driver2.findElement(By.xpath("//*@id='webLossReport.contact.address.state']")),index=i);
4

3 回答 3

3

你不知何故迷失在 Selenium RC 和 Selenium WebDriver 之间。假设您想使用 WebDriver,请参阅此文档,它解释了一切

您可以执行以下操作 - 它直接<option>在指定的第三个标签中找到<select>并单击它:

driver.findElement(By.xpath("id('selectsId')/option[3]")).click();

或者这个使用Select

Select sel = new Select(driver.findElement(By.id("selectsId")));
sel.selectByIndex(3);
于 2012-07-12T00:40:45.560 回答
1

在 C# 中,我用这个解决了:

selenium.Select("id=yourID", "index=" + i.ToString());
于 2015-07-31T12:58:00.133 回答
0

我不熟悉这个库,但Selenium 参考页面给出了以下签名select

select(java.lang.String selectLocator, java.lang.String optionLocator)

在您的代码中,第二个参数是index=i分配index给 的值i,然后返回该int。您打算将什么字符串作为第二个参数传递?"index=i"? "index=" + i?

于 2012-07-11T23:34:27.940 回答