选择下拉使用Selenium每个选项 [英] select each option in a dropdown using Selenium
问题描述
我不能够选择在下拉列表中选择。我想,我需要有。选择
或 SelectElement
,但目前还没有这样的选项。
示例代码:
IWebDriver ffbrowser =新FirefoxDriver();
ffbrowser.Navigate()GoToUrl(http://www.amazon.com/);
ffbrowser.Manage()Window.Maximize();
的Thread.Sleep(500);
IWebElement DDL = ffbrowser.FindElement(By.Name(URL));
INT numofitems = ddl.FindElements(By.TagName(选项))计数。
的for(int i = 1; I< numofitems;我++)
{
ffbrowser.select(变量名=选项,指数= I);
}
中ffbrowser.select,选择的报告为错误:
错误1'OpenQA.Selenium.IWebDriver'不包含'选择'的定义,并没有扩展方法中,选择接受式的第一个参数OpenQA.Selenium .IWebDriver'可以找到(是否缺少using指令或程序集引用?)
我的项目引用包括 Selenium.WebDriverBackedSelenium
, Thoughtworks.Selenium.Core
,的webdriver
, WebDriver.Support
和我有
使用NUnit。架构;
使用OpenQA.Selenium;
使用OpenQA.Selenium.Chrome;
使用OpenQA.Selenium.Firefox;
使用OpenQA.Selenium.IE;
使用OpenQA.Selenium.Support.UI;
根据的webdriver你使用,你可以什么版本硒使用 SelectElement
类,这将包括在 OpenQA.Selenium.Support.UI
。结果
为例:结果
SelectElement选择=新SelectElement(元);
selector.SelectByIndex(1);
凡的元素的是你的下拉框。
I'm not able to select options in a dropdown list. I think I need to have .Select
or SelectElement
, but there is no such option.
Sample code:
IWebDriver ffbrowser = new FirefoxDriver();
ffbrowser.Navigate().GoToUrl("http://www.amazon.com/");
ffbrowser.Manage().Window.Maximize();
Thread.Sleep(500);
IWebElement ddl = ffbrowser.FindElement(By.Name("url"));
int numofitems = ddl.FindElements(By.TagName("option")).Count;
for (int i = 1; i < numofitems; i++)
{
ffbrowser.select("TagName = option", "index = i");
}
The "select" in "ffbrowser.select" is reported as an error:
Error 1 'OpenQA.Selenium.IWebDriver' does not contain a definition for 'select' and no extension method 'select' accepting a first argument of type 'OpenQA.Selenium.IWebDriver' could be found (are you missing a using directive or an assembly reference?)
My project references include Selenium.WebDriverBackedSelenium
, Thoughtworks.Selenium.Core
, WebDriver
, WebDriver.Support
and I have
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
Depending what version of Selenium WebDriver you are using you can use the SelectElement
class, which will be included in OpenQA.Selenium.Support.UI
.
For example:
SelectElement selector = new SelectElement(element);
selector.SelectByIndex(1);
Where the element is your drop down box.
这篇关于选择下拉使用Selenium每个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!