Question

I am trying to identify a WebElement in Mozilla browser using the xpath. Below is the html code:

<div id="address-book" class="grid-12" style="display:none;">
<!-- END ADDRESS BOOK -->
<!-- BEGIN PAYMENT OPTIONS -->
<div id="paymentSection" class="grid-12 form-section">
<div class="grid-contentx">
<div class="hd header-container">
<h3>Payment Information</h3>
</div>
</div>
<!-- BEGIN: CC FORMS -->
<div class="grid-6">

The relevant xpath I wrote in the page object factory is:

@FindBy(xpath = "//*[@id='paymentSection']/div[1]/div/h3")
private WebElement paysection;

Upon running the script, I am getting an error message "unable to identify the element". Please help me if there is any correction to be done to the identified xpath.

Was it helpful?

Solution

There are many xpaths which can help you locate h3 in the above case, let me list down a few :

using id :

xpath = "//div[@id='paymentSection']//h3"

using text :

xpath = "//h3[contains(.,'Payment Information')]"

using class names :

xpath = "//div[@id='paymentSection']//div[@class='hd header-container']/h3"

using combination of id and class name :

xpath = "//div[@id='paymentSection' and @class='grid-12 form-section']//h3"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top