Simple Object Positioning:
Webdriver provides a range of element positioning methods, which are commonly used in the following ways:
- Id
- Name
- Class name
- Tag name
- Link text
- Partial link text
- Xpath
- CSS Selector
The methods that correspond to Python webdriver are:
FIND_ELEMENT_BY_ID ()
Find_element_by_name ()
Find_element_by_class_name ()
Find_element_by_tag_name ()
Find_element_by_link_text ()
Find_element_by_partial_link_text ()
Find_element_by_xpath ()
Find_element_by_css_selector ()
1) ID and name locator:
ID and name are our most common targeting methods, because most elements have these two properties, and in the ID and name of the control
Naming usually makes it meaningful and takes a different name. These two properties make it fairly easy for us to find properties on a page.
HTML code:
<input id= "gs_htif0" class= "Gsfi" aria-hidden= "true" dir= "ltr" >
<input type= "Submit" Name= "BTNK" jsaction= "Sf.chk" value= "Google Search" >
<input type= "Submit" Name= "Btni" jsaction= "Sf.lck" value= "Good luck" >
The element is positioned with the ID and name attribute in the element:
Id= "Gs_htif0"
find_element_by_id ("gs_htif0")
Name= "BTNK"
Find_element_by_name ("BTNK")
Name= "Btni"
Find_element_by_name ("Btni")
Simple Object Positioning