Showing posts with label Finding locators in selenium. Show all posts
Showing posts with label Finding locators in selenium. Show all posts

Sunday, August 19, 2012

Finding the locators using selenium


Direct Reference  Using one of the direct references to the HTML element
Id=MyButton (note in this case, “Id =” is not even required)
Name=Description_Field
Value=ABC XYZ
Link=Contact Us

XPath, (XML Path Language)  :xpath, for locators starting with "//"
Reference: http://www.w3schools.com/xpath/default.asp Relatively straightforward to compose and read later down the track.
xpath=//img[@alt='The image alt text']
xpath=//table[@id='table1']//tr[4]/td[2]
xpath=//a[contains(@href,'#id1')]
xpath=//a[contains(@href,'#id1')]/@class
xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
xpath=//input[@name='name2' and @value='yes']
xpath=//*[text()="right"]
/html/body/div[1]/div[5]/div/table/tbody/tr/td/p/a[3] (An example bad XPath – it will break as soon as the page layout changes a bit)


DOM and CSS : 
dom=document.images[0] (the first image in the page)
css=H1.topic (the first heading with the class name of topic) or css=h1.topic[value="Topic Index"] (the heading with the specific text)
dom=document.forms['myForm'].myDropdown
dom=document.images[56]
dom=function foo() { return document.links[1]; }; foo();
css=a[href="#id3"]
css=span#firstChild + span

Keyboard and Coordinates
You can also go to the extreme of KeyDown and KeyUp