- maggiexg
- Posts : 3
Join date : 2009-09-23
How to create/recognize object element not using recording?
Wed Sep 23, 2009 4:17 am
Hi,
I have the following questions:
1. How to create an object element not using recording method?
for example, by scripting
clickandwait
Go (image link)
Will Selenium find the Go link on the page? Can we use the labels on the screen to run as many actions as we like this way?
2. How Selenium recognize a UI element?
Thanks,
MX
I have the following questions:
1. How to create an object element not using recording method?
for example, by scripting
clickandwait
Go (image link)
Will Selenium find the Go link on the page? Can we use the labels on the screen to run as many actions as we like this way?
2. How Selenium recognize a UI element?
Thanks,
MX
Re: How to create/recognize object element not using recording?
Wed Sep 23, 2009 10:58 am
hi,
If you want to create script manually not using record and play feature of selenium, it is simple.
For this you have to start you application and IDE. Suppose you have login page and you want to create object for all object present on that screen. The following are steps:
1. go to first element username field, right click with mouse. It will show some command of selenium in mouse popup. select verifyElementPresent.
2. Moe one step is recorded in selenium ide. go and have a look.
3. Now modify that command, do type instead of verifyElement.
4. leave the Target field, it is your object locator.
5. Type username in value option of IDE.
By this way you can get object of any element and modify according to your need. Selenium will not find "GO" you have to provide actual dom locator or xpath.
Selenium will recognize the element in following ways:
Element Locators tell Selenium which HTML element a command refers to.
The format of a locator is:
strategies:
Hope this will help you. Best of luck.
Bye
If you want to create script manually not using record and play feature of selenium, it is simple.
For this you have to start you application and IDE. Suppose you have login page and you want to create object for all object present on that screen. The following are steps:
1. go to first element username field, right click with mouse. It will show some command of selenium in mouse popup. select verifyElementPresent.
2. Moe one step is recorded in selenium ide. go and have a look.
3. Now modify that command, do type instead of verifyElement.
4. leave the Target field, it is your object locator.
5. Type username in value option of IDE.
By this way you can get object of any element and modify according to your need. Selenium will not find "GO" you have to provide actual dom locator or xpath.
Selenium will recognize the element in following ways:
Element Locators tell Selenium which HTML element a command refers to.
The format of a locator is:
We support the following strategies for locating elements:
locatorType=argument
Without an explicit locator prefix, Selenium uses the following default
identifier=id
Select the element with the specified @id attribute. If no match is
found, select the first element whose @name attribute is id.
(This is normally the default; see below.)
id=id
Select the element with the specified @id attribute.
name=name
Select the first element with the specified @name attribute.
- username
- name=username
The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.
- name=flavour value=chocolate
dom=javascriptExpression
Find an element using Javascript traversal of the HTML Document Object
Model. DOM locators must begin with "document.".
- dom=document.forms['myForm'].myDropdown
- dom=document.images[56]
xpath=xpathExpression
Locate an element using an XPath expression.
- xpath=//img[@alt='The image alt text']
- xpath=//table[@id='table1']//tr[4]/td[2]
link=textPattern
Select the link (anchor) element which contains text matching the
specified pattern.
- link=The link text
css=cssSelectorSyntax
Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors
for more information. You can also check the TestCssLocators test in
the selenium test suite for an example of usage, which is included in
the downloaded selenium core package.
- css=a[href="#id3"]
- css=span#firstChild + span
Currently the css selector locator supports all css1, css2 and css3
selectors except namespace in css3, some pseudo classes(:nth-of-type,
:nth-last-of-type, :first-of-type, :last-of-type, :only-of-type,
:visited, :hover, :active, :focus, :indeterminate) and pseudo
elements(::first-line, ::first-letter, ::selection, ::before, ::after).
strategies:
dom, for locators starting with "document."
xpath, for locators starting with "//"
identifier, otherwise
Hope this will help you. Best of luck.
Bye
- maggiexg
- Posts : 3
Join date : 2009-09-23
Re: How to create/recognize object element not using recording?
Wed Sep 23, 2009 11:38 am
Hi Adviser,
Thanks for the detailed explainations and I found the context menu by following your steps. It is so helpful!
MX
Thanks for the detailed explainations and I found the context menu by following your steps. It is so helpful!
MX
- kmahata@gmail.comActive particpant
- Posts : 10
Join date : 2009-11-06
Re: How to create/recognize object element not using recording?
Sat Nov 07, 2009 2:48 pm
Hi Maggie
U may use Firebug addon in FF. Through this u can know the locators. Capture them and type the command u want to perform on them
U may use Firebug addon in FF. Through this u can know the locators. Capture them and type the command u want to perform on them
Permissions in this forum:
You cannot reply to topics in this forum
|
|