XPath Locator using (contains), text property of element and finding xpath for child at any level of parent.
using 'contains' in xpath
Lets try to find xpath locator of new button in above shown picture. 'New' button has attribut 'id' with value 'menubutton19'. Now '19' seems to be number which may change. So lets take substring of value and use 'menubutton' ie substring of complete value. The xpath of above element can be created by using the contains keyword
which has the syntax contains(@attribute,'value')
and xpath becomes //tagname[contains(@attribute,'value') ]
which is //button[contains(@id,'menubutton')
Now this is not unique.
Locating child element at any level(//) and using text property of element in xpath
There is one element 'span' located inside the 'button' element which has 'text' property 'New'. We can use this text property to uniquely find the element. Here we will use (//) in xpath to tell xpath locator that element is anywhere within the parent. Otherwise if we use (/), it denotes that element is immediately below the parent.
so the xpath becomes:
//button[contains(@id,'menubutton')]//span[text()='New']
Note: text property has to be suffixed with ()
***************************************************************************************
QACult Best Software Testing Courses in Chandigarh tricity.- We love to enhance your knowledge.
QACult is the premier institute catering to the requirements of experienced and fresh pass-out that gives leaders like you a new way to experience Quality engineering—while you work and giving you the flexibility to both advance your career.
Our faculty have 12+ years of industrial experience and have developed many automation testing frameworks in java using TestNG or BDD (cucumber) methodology. We expertise in developing automation testing frameworks in java, python, javascript, php, ruby(WATIR-webdriver & Capybara) and Appium.
please subscribe our channel for more such updates:
Our faculty have 12+ years of industrial experience and have developed many automation testing frameworks in java using TestNG or BDD (cucumber) methodology. We expertise in developing automation testing frameworks in java, python, javascript, php, ruby(WATIR-webdriver & Capybara) and Appium.
please subscribe our channel for more such updates:
And visit for website: www.qacult.com for various blogs and Upcoming Events.
Comments
Post a Comment