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 Testing Tools Cookbook》这本图书作为学习资源的价值。Selenium WebDriver作为测试自动化领域的重要工具,随着Web技术的不断发展,它在测试...
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 ...
Selenium是一个广泛使用的自动化测试工具,特别是在Web应用测试领域。它为测试人员提供了一套丰富的API,允许他们利用多种编程语言来编写测试脚本,以便于自动化浏览器操作。Selenium2TestingToolsBeginner'sGuide是...
PidginHost Selenium Plugin & SSH Testing Suite
标题:Automation Testing Sharing 描述:十年自动化测试介绍和经验总结!不可不看! 知识点: 一、为什么选择自动化测试(Why Automated Testing) 自动化测试是软件测试领域的重要组成部分,它利用专用的测试...
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...
selenium 2.53.1 for windows selenium 2.53.1 for windows
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, ...
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 ...
标题和描述均提到了“web automation testing”,这指的是在网页应用上执行自动化测试的过程,以确保网站的功能性、性能和可靠性。关键词“baidu”暗示了这种测试可能应用于百度这样的大型互联网公司或其产品上。...
此自动化测试框架结合项目实例展示了,如何通过webDriver junit maven svn构建集成自动化测试过程
《Packtpub Selenium 1.0 Testing Tools Beginners Guide Nov 2010》是一本针对初学者的Selenium测试工具指南,旨在帮助读者理解和掌握自动化Web应用测试的基础知识。Selenium是一个广泛使用的开源自动化测试框架,...
《Selenium Testing Tools Cookbook》是一本专为自动化测试新手量身打造的指南,它深入浅出地介绍了如何利用Selenium工具进行高效的Web应用程序自动化测试。Selenium作为一个强大的开源自动化测试框架,广泛应用于...
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 ...