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

Why Jmeter is best option for Performance Testing?

There are multiple tools in market for performance testing of any software but Jmeter is the best solution among all of them due to some reason listed below 1) Jmeter is the open source application so users who use this application will not to pay anything. 2) You can use Jmeter for performance of any web application,  Databases and Web Services (REST and SOAP APIs). 3) Jmeter have the user friendly UI component so it is very easy to use. 4) Jmeter can be used to simulate to put maximum number of concurrent users on a server, network or object to test its strength or to analyze overall performance under different load types. 5) Jmeter also use for functional testing for static( JavaScript and HTML) and dynamic( JSP, Servlets and AJAX) resources. 6) Jmeter provides Verity of graphical representations for performance report so it is easy to understand.

How You Can Test Database?

Now we know the Database Testing which you can learn in my last article. In this article we will discuss about the steps that need to following to test any Database. Database Tester should have some basic knowledge regarding SQL Command like DDL (create/drop),  DML (Insert/Delete/Update) and DCL (Grant/Revoke).

Causes of Software Defects

It is practically impossible that developer develop a bug free software and that software we can deliver without Testing. If the complexity of the software increased then there must be bugs that can harm the users who will use that software.