此方法一般很少用。看了selenium的源码。下面首先看一下selenium的doSelect方法。也就是我们在选择下拉菜单用的select方法。可以通过index,label,value,id四种方式来select下拉菜单中的option。
doSelect源码如下:
Selenium.prototype.doSelect = function(selectLocator, optionLocator) {
/**
* Select an option from a drop-down using an option locator.
*
* <p>
* Option locators provide different ways of specifying options of an HTML
* Select element (e.g. for selecting a specific option, or for asserting
* that the selected option satisfies a specification). There are several
* forms of Select Option Locator.
* </p>
* <ul>
* <li><strong>label</strong>=<em>labelPattern</em>:
* matches options based on their labels, i.e. the visible text. (This
* is the default.)
* <ul class="first last simple">
* <li>label=regexp:^[Oo]ther</li>
* </ul>
* </li>
* <li><strong>value</strong>=<em>valuePattern</em>:
* matches options based on their values.
* <ul class="first last simple">
* <li>value=other</li>
* </ul>
*
*
* </li>
* <li><strong>id</strong>=<em>id</em>:
*
* matches options based on their ids.
* <ul class="first last simple">
* <li>id=option1</li>
* </ul>
* </li>
* <li><strong>index</strong>=<em>index</em>:
* matches an option based on its index (offset from zero).
* <ul class="first last simple">
*
* <li>index=2</li>
* </ul>
* </li>
* </ul>
* <p>
* If no option locator prefix is provided, the default behaviour is to match on <strong>label</strong>.
* </p>
*
*
* @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
* @param optionLocator an option locator (a label by default)
*/
var element = this.browserbot.findElement(selectLocator);
if (!("options" in element)) {
throw new SeleniumError("Specified element is not a Select (has no options)");
}
var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
var option = locator.findOption(element);
this.browserbot.selectOption(element, option);
};
doAddSelection的源码如下
Selenium.prototype.doAddSelection = function(locator, optionLocator) {
/**
* Add a selection to the set of selected options in a multi-select element using an option locator.
*
* @see #doSelect for details of option locators
*
* @param locator an <a href="#locators">element locator</a> identifying a multi-select box
* @param optionLocator an option locator (a label by default)
*/
var element = this.browserbot.findElement(locator);
if (!("options" in element)) {
throw new SeleniumError("Specified element is not a Select (has no options)");
}
var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
var option = locator.findOption(element);
this.browserbot.addSelection(element, option);
};
如果下拉菜单中没有以上标签除index之外,可以通过addSelection这个方法来添加选项。
例如:
<ul class="menu">
<li>test="a"</li>
<li>test="b"</li>
</ul>
我们就可以用selenium.addSelection("//ul[@class='menu']","test")
selenium.select("test=xxx");
以上纯属于个人研究,如果有什么不对的,请指教,共同学习。谢谢。
- 浏览: 12939 次
- 性别:
- 来自: 上海
相关推荐
selenium IDE之add selection学习样例side文件,下载后用IDE打开可直接运行
Selenium 官方中文文档
Selenium官方中文文档
生成的测试脚本可以用Selenium Core手工执行,也能基于Selenium RC放入Java,C#,Ruby的单元测试用例中自动运行。 3. 测试用例调用实际的浏览器(如IE、FireFox)来执行测试。 和有些开源方案自行实现Web解释引擎...
selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium selenium
selenium-doc, selenium 中文文档
Selenium中文API.pdf
这份文档是在入门文档的基础上增加了一些实际的例子。 包括:验证码的识别、Excel的读取等等(含源代码)
selenium中文API,包含selenium的函数使用介绍整理。
selenium中python常用函数
Selenium 不同于一般的测试工具。一般的脚本测试工具录制脚本,实际上都是通过拦截 ... 当然,对那些执行压力测试的工具来说,这类模拟已经足够。...种语言的使用方法都是一样的。下面,我以Java 为例进行说明。
Selenium WebDriver + ReportNG 中文乱码问题解决方案。
selenium使用说明selenium使用说明selenium使用说明selenium使用说明selenium使用说明selenium使用说明selenium使用说明
Selenium 中文API 自动化测试工具
selenium中文API.pdf
selenium selenium selenium
Selenium_v2.5 Selenium_v2.5 Selenium_v2.5 Selenium_v2.5Selenium_v2.5 Selenium_v2.5
Selenium中文API参考手册.pdf
文档来源采集离线html源 http://selenium-python-zh.readthedocs.io/en/latest/getting-started.html 文档类型,离线html整合 ,整理成了离线chm格式的