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.

Smoke Testing

In Smoke Testing, Testing team check the key feature or key bugs of the software. Smoke testing ensure that critical functionality of the software is working fine.If key features are not working then it is no needed to test the overall functionality because it is just waste of time. In Smoke Testing, test team check the basic feature of the software and if basic feature is not working it means software is broken very badly and further testing is unnecessary. If Smoke Testing failed then it is declared that build is unstable and revert back to developer team until smoke test is pass.

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.