Different Ways to Find XPATH with examples:
//input[@type= ‘email’ or @name= ‘email’]
//*[contains (@placeholder, ‘Organization)]
//a[starts-with(text(), 'START')]
//input[starts-with(@name, ‘organization)]
//button[contains(text(),’ Signup’ )]
//div[@class= ’ col-sm-12 google-sign-form’]/input[2]
//ul[@class=’nav navbar-nav navbar-right’]//li[@class=’
//input[@name=’ organization_name’]//
//li[@class=’sign-in’]//
//input[@name=’password’]//
//li[@class=’login’]//
//div[@class=’ col-sm-12 google-sign-form’]/child::
//input[@name=’email’]//
//div[@class=’ col-lg-3 col-md-4 col-sm-6 sign-form’]//descendant:: input
//input[@name=’email]//
Types Of XPath in Selenium2.1 Absolute
2.2 Relative
Writing Dynamic XPath in Selenium by different ways:
3.1 Basic XPath
3.2 Using ‘OR’ & ‘AND’
3.3 Using Contains()
3.4 Using Starts-With
3.5 Using Text()
3.6 Using Index
3.7 Using Chained XPath
3.8 XPath Axes
3.8.1 Following
3.8.1.1 Following Sibling
3.8.2 Preceding
3.8.2.1 Preceding Sibling
3.8.3 Child
3.8.4 Parent
3.8.5 Descendants
3.8.6 Ancestors
2.2 Relative
Writing Dynamic XPath in Selenium by different ways:
3.1 Basic XPath
3.2 Using ‘OR’ & ‘AND’
3.3 Using Contains()
3.4 Using Starts-With
3.5 Using Text()
3.6 Using Index
3.7 Using Chained XPath
3.8 XPath Axes
3.8.1 Following
3.8.1.1 Following Sibling
3.8.2 Preceding
3.8.2.1 Preceding Sibling
3.8.3 Child
3.8.4 Parent
3.8.5 Descendants
3.8.6 Ancestors
or
//*[@attribute_name='
//input[@id='Email']
or
//*[@id='Email']
Multiple Attribute://<HTML tag>[@attribute_name1='
or
//*[@attribute_name1='
//input[@id='Email'][@name='
or
//*[@id='Email'][@name='
Using AND://<HTML tag>[@attribute_name1='
or
//*[@attribute_name1='
//input[@id='Email' and @name='Email']
or
//*[@id='Email' and @name='Email']
Using OR://<HTML tag>[@attribute_name1='
or
//*[@attribute_name1='
//input[@id='Email' or @name='Email']
or
//*[@id='Email' or @name='Email']
contains()://<HTML tag>[contains(@attribute_name, 'attribute_value')]
or
//*[contains(@attribute_name, 'attribute_value')]
//<HTML tag>[contains(@attribute_name, 'attribute_value')]
or
//*[contains(@attribute_name,' attribute_value')]
//input[contains(@id,'Email')]
or
//*[contains(@id,'Email')]
or
//input[contains(@name,' Email')]
or
//*input[contains(@name,' Email')]
starts-with()://<HTML tag>[starts-with(@attribute_ name,'attribute_value')]
or
//*[starts-with(@attribute_ name,'attribute_value')]
//input[starts-with(@id,'Ema') ]
or
//*[starts-with(@id,'Ema')]
text()://*[text()='New look for sign-in coming soon']
last():findElement(By.xpath("(// input[@type='text'])[last()]") )
[last()-1] – Selects the last but one element (of mentioned type) out of all input element present
findElement(By.xpath("(// input[@type='text'])[last()-1] "))
position():findElement(By.xpath("(// input[@type='text'])[position( )=2]"))
or
findElement(By.xpath("(// input[@type='text'])[2]"))
Finding elements using index
findElement(By.xpath("//label[ 2]"))
following: //*[@id='FirstName']
To identify the input field of type text after the FirstName field, we need to use the below xpath.
//*[@id='FirstName']/ following::input[@type='text']
To identify just the input field after the FirstName field, we need to use the below xpath.
//*[@id='FirstName']/ following::input
preceding://*[@id='LastName']
//*[@id='LastName']// preceding::input[@type='text'] "
or
//*[contains(@attribute_name,
//<HTML tag>[contains(@attribute_name,
or
//*[contains(@attribute_name,'
//input[contains(@id,'Email')]
or
//*[contains(@id,'Email')]
or
//input[contains(@name,'
or
//*input[contains(@name,'
starts-with()://<HTML tag>[starts-with(@attribute_
or
//*[starts-with(@attribute_
//input[starts-with(@id,'Ema')
or
//*[starts-with(@id,'Ema')]
text()://*[text()='New look for sign-in coming soon']
last():findElement(By.xpath("(//
[last()-1] – Selects the last but one element (of mentioned type) out of all input element present
findElement(By.xpath("(//
position():findElement(By.xpath("(//
or
findElement(By.xpath("(//
Finding elements using index
findElement(By.xpath("//label[
following: //*[@id='FirstName']
To identify the input field of type text after the FirstName field, we need to use the below xpath.
//*[@id='FirstName']/
To identify just the input field after the FirstName field, we need to use the below xpath.
//*[@id='FirstName']/
preceding://*[@id='LastName']
//*[@id='LastName']//
No comments:
Post a Comment