Skip to main content

XPath Expression to locate Web Element

In last article i mentioned you how to locate the Web Element with id, Name, LinkText, Partial LinkText, CSS Selectors, Class Name and Tag Name. We use FireBug add-one to use these 7 locators to locate the Web Element on Web Page. Now we are talking about XPath expression. Which is also a type of Locator. We need FirePath add-ons to use it.

XPath can be identify in 2 ways

1. Absolute XPath: Absolute XPath is identify and generated from the root node. In Absolute XPath a prefix "/" is added.

/html/body/div/div/div/div/form/fieldset/div/input[@id='email']

let me show you a snapshot how to get it
Selenium Web Driver, XPath , Locators, Absolute Xpath, Automation Testing

2. Relative XPath: In Relative Xpath the node will be from where you want to start and it start with the "//". In Relative Xpath we do not need to start from the root node.

Below is the image for which i will write down the various method to write Relative XPath
Relative XPath, Automation Testing, Selenium Web Driver, Locators

Below is the code that showing in above screen shot
<div id="gaia_firstform" class="form-panel first valid">
<div class="slide-out ">
<div class="input-wrapper focused">
<div id="identifier-shown"><div>
<label class="hidden-label" for="Email">   Enter your email</label>
<input id="Email" type="email" autofocus="" spellcheck="false" value="" placeholder="Enter your email" name="Email"/>
<input id="Passwd-hidden" class="hidden" type="password" spellcheck="false"/>
</div>
</div>
<span id="errormsg_0_Email" class="error-msg" role="alert"/>
</div>


a. When you click on the FirePath always you have a XPath. For this a XPath is showing

.//*[@id='Email']

b. By using tag name and attribute 

//input[@id='Email']
//input[@type='email']
//input[@name='Email']
//input[@placeholder='Enter your email']

c. to locate the element by using  XPath where some text is visible on the web page

See the below image to locate Web page
Absolute XPath, Automation Testing, Locators, Relative XPath, Selenium Web Driver, XPath Locators

 To locate this "Create account" web element following will be the XPath. By using contains keyword user need to put some text of whole line that need to locate. 

//a[contains(text(),'Create account')]
d.To locate the link by using contains keyword below is the code



//a[contains(@href,'https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail&hl=en')]

Comments

Popular posts from this blog

What is API?

In general way, API (Application Programming Interface) is the intermediate software which is useful for two applications to communicate. API is the tool which is used for interaction of two applications. If developer developing any software which have multiple blocks (Modules) than developer use APIs to put them together.

How to Put Load on a Script in JMeter

In last post we discussed about how to record a test script and Firefox settings to run the script. In this post we will discuss about how the Thread Group will work, how can we put n number of users to perform load testing, In JMeter by using Thread Group, we can create virtual users. Thread Group is a set of thread which work in same scenario. There are multiple thread group are available which is use to configure how the virtual users interest with the application, How much load maintain and till how much time load maintain.

Why testing is necessary?

Before start learning of Testing i would like to ask one thing - why testing is necessary? In each and every field 'Testing' is the important phase of product development cycle. Without testing no one ensure the quality of the product. The product can be anything it may be a Car, a Machine, a Medicine , a Software etc, it need to fully tested. Only after testing you can say the product that you build have good quality. Only after testing you can release your product in market. if you release your product in market without testing then it may be possible that your product have serious issue that cause the negative effect on your business. So Testing on important. Now we talk about the Testing importance in Software Development. Testing is necessary because everyone makes mistakes and sometimes these errors are expensive or dangerous. Testing is required to test every part because things can always go wrong. Today is the market of Internet and if you leave any mist...