0

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.

Richard
  • 8,961
  • 3
  • 38
  • 47
Ak17
  • 75
  • 3
  • 15

1 Answers1

0

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"
Amith
  • 6,818
  • 6
  • 34
  • 45
  • I have tried with all the above options but still I am facing unable to locate the element error.Please help me out if there is any work around for the issue – Ak17 Mar 19 '14 at 10:07
  • I have not used the wait for the element as the page under which the application under test will be there for a while and has a good amount of time to identify the element. – Ak17 Mar 20 '14 at 05:47
  • I just rechecked and "//div[@id='paymentSection' and @class='grid-12 form-section']//h3" worked.Thanks for the help! – Ak17 Mar 20 '14 at 07:21