Selenium
Commands For Automation Testing
一、Element
Locators(定位器)
id locator (Select the element with the specified @id attribute in HTML).
name locator(Select the first element of the same @name attribute elements
in HTML).
identifier locator (First,select the element with the specified @id
attribute in HTML.IF it is not extant,then Select the first element of the same
@name attribute elements in HTML).
dom locator (Using javascriptExpression locate the element of HTML.
Note:must start by 'document').
Example:
dom=document.forms['myForm'].myDropdown
dom=document.images[56]
xpath locator (Locate the element in HTML by XPath. Note:must start by
'//')
Example:
xpath=//img[@alt='The
image alt text']
xpath=//table[@id='table1']//tr[4]/td[2]
link
locator (Select the link (anchor) element which contains text matching the
specified pattern).
Example:
link=The
link text
Without an explicit locator prefix, Selenium uses the following default
strategies:
dom, for locators starting with
"document."
xpath, for locators starting with
"//"
identifier, otherwise
二、Actions(模仿用户操作)
Imitate
user's actions: Action have two format: 'action' and
'actionAndWait', action will execute at once,but 'actionAndWait' will wait for a
setting time to get the response of this action. 'open'
can deal latency time itself.
click(elementLocator)
- Click link,button,radio or checkbox button.
- If needing latency time for new page response ,please use "waitForPageToLoad"
Example:
selenium.click("xpath=//div[@id='dd']");
open(url)
- Open page using URL in Borwer, the action could receive two formats of relative path and absolute path.
Example:
selenium.open("http://www.google.cn");
selenium.open("/login.jsp");
type(inputLocator, value)
- Imitate the process of user typing, type value to inputLocator.
- also is fit for radio or checkbox.
contextMenu(locator)
- Right-click link, button, radio or checkbox button.
三、Execute
JavaScript(执行JS脚本)
Launch page, then using selenium Server execute JavaScripte code for some useful function.
getEval(String script)
- script: some JavaScript code string.
- getEval: execute script and get the return value.
Example:
selenium.getEval("return document.getElementById('test').attribute('value');");
四、Execute
Flex Script(执行Flex脚本)
Launch page, then using selenium Server execute JavaScripte code to call Flex function APIs.
getEval(String script)
--Precondition: The flash object is in current executing page and this flash has function APIs.
--First: Using javascript DOM find the locator of flash object id.
- Second: Exectue the function of Flex function APIs of this object locator.
- Third: GetEval function execute script and get the return value.
Example:
String text = "selenium.browserbot.getCurrentWindow().document.getElementById('testFlash').addNode('nodename','parentNodeName','true');";
selenium.getEval(text);
五、Using
XPath(如何使用XPath定位元素)
Show some useful method to locator element using XPath.
- Don't using id locator unless the id of this element is stable or you can't find other ways.
Example:
selenium.click("xpath=//div[@id='test']");
(If the id is not stable, your code is not safe.)
- Common useful Path Expression
nodename
|
Locate
all children nodes of this node
|
/
|
Locate
all node for root node
|
//
|
Locate
node from current select node, don't care about the location of selected
node.
|
.
|
Choice
current selected node
|
..
|
Choice
parent node of current selected node
|
@
|
Locate
node using attribute
|
Example:
booknode
|
Locate
all children nodes of the node named 'booknode'
|
/booknode
|
Locate
root node named 'booknode'
|
//book
|
Locate
all node named 'book', don't care about the location of selected node.
|
//book[@value='1']
|
Locate
node named 'book' and attribute of value equal 1.
|
- Useful function of location
--text(): Return text value of the element. Like <span>ddd</span>, return ddd.
--contains(String A, String B): If A contains B return true, else return false.
--last(): Return the last node of choice nodes.
Example:
selenium.click("xpath=//div[contains(text(),'Released Projects')]");
(Click the div which text contains 'Released Projects' string.)
--First: xpath=//span[contains(text(),'Released Projects')]/../..//img[@class='dijitTreeExpando dijitTreeExpandoClosed']
(Locate an image tag which is a sub node of the parent node of the parent node of span node which text contains 'Released Projects'.)
--Second: xpath=//label[@title='level1FolderName']/../../../..//label[@title='level2FolderName']/../../../img
--Third: xpath=//span[@class='dijitDialogTitle' and text()='Users/Groups Filter']
六、Reference(参考)
分享到:
相关推荐
Selenium 私房菜,系统的介绍WebDriver,比较全面的一本selenium的自动化书籍
By the end of the book, you will be able to design your own automation testing framework and perform data-driven testing with Selenium WebDriver. Contents 1: BUILDING A SCALABLE SELENIUM TEST DRIVER ...
This book is intended for software quality assurance/testing professionals, software project managers, or software developers with prior experience in using Selenium and Java to test web-based ...
If you are a quality testing professional, or a software or web application developer looking to create automation test scripts for your web applications, with an interest in Python, then this is the ...
one of the best selenium automation testing guide book
Set up Selenium Grid for faster and parallel running of tests, increasing test coverage and reducing test execution time for cross-browser testing Build extended Selenium WebDriver tests for ...
Selenium WebDriver is a popular automated testing tool for web applications. Python is one of the top programming languages and when used with Selenium it can automate and test web applications. Using...
Utilize Selenium WebDriver features for automation testing using outstanding techniques and strategies Learn how to build, customize, and maintain Selenium frameworks Packed with numerous practical...
selenium 2.53.1 for windows selenium 2.53.1 for windows
Packtpub.Selenium.2.Testing.Tools.Beginners.Guide.Oct.2012.pdf
This package contains some popular automation testing library for RF, these library can be installed by pip locally without internet access. pip should be installed first. It includes SSHLibrary, ...
Packtpub.Selenium.1.0.Testing.Tools.Beginners.Guide.Nov.2010.rar
英文版的电子书,从入门开始介绍selenium2.0, 也就是webdriver. 学习selenium webdriver的必备神器!
Utilize Selenium WebDriver features for automation testing using outstanding techniques and strategies Learn how to build, customize, and maintain Selenium frameworks Packed with numerous practical ...
此自动化测试框架结合项目实例展示了,如何通过webDriver junit maven svn构建集成自动化测试过程
Selenium2.0 for chromedriver
using TestNG to create your own automation framework.By the end of this Learning Path, you'll be able to design your own automation testing framework and perform data-driven testing with Selenium ...
Learning Selenium Testing tools with python.pdf 英文版
不错的啊,学习Selenium rc for java很好的
Selenium Testing Tools Cookbook Over 90 recipes to build, maintain, and improve test automation ...Explains testing of mobile web applications with Selenium Drivers for platforms such as iOS and Android