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.

JMeter Overview Description

In this article we will go through the multiple section of JMeter and describe the tool information. we will discuss about every component of JMeter tool in this Article so that you can hands on while working on script on JMeter about these components.