Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:39:38+00:00 2026-05-27T03:39:38+00:00

I have the following HTML on a page that I am trying to test

  • 0

I have the following HTML on a page that I am trying to test with cucumber.

<div class='try_options'>
  <ul>
    <li>
      <div>
        <img alt="" src="/images/main_page1.jpg" />
        <div class='right_section'>

          <p>
            Feature 1
          </p>
          <a class='suggest_btn' href='url1'>Try Now</a>
        </div>
      </div>
    </li>
    <li>
      <div>
        <img alt="" src="/images/main_page2.jpg" />
        <div class='right_section'>

          <p>
            Feature 2
          </p>
          <a class='suggest_btn' href='url2'>Try Now</a>
        </div>
      </div>
    </li>
    <li>
      <div>
        <img alt="" src="/images/main_page3.jpg" />
        <div class='right_section'>

          <p>
            Feature 3
          </p>
          <a class='suggest_btn' href='url3'>Try Now</a>
        </div>
      </div>
    </li>
    <li>
      <div>
        <img alt="" src="/images/main_page4.jpg" />
        <div class='right_section'>

          <p>
            Feature 4
          </p>
          <a class='suggest_btn' href='url4'>Try Now</a>
        </div>
      </div>
    </li>
  </ul>
</div>

Basically, there are features, each with a “Try Now” link. I want to test if clicking on the link takes me to the page for the respective feature.

I found a simalar step implementation here, but there is something wrong with the XPATH. Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:39:38+00:00Added an answer on May 27, 2026 at 3:39 am

    When I’ve done something similar before, I’ve used XPath to locate the ‘identifier’ element – in your case the p tag containing e.g. ‘Feature 1’, then walked up the DOM to a common parent (li here), and down again to find whatever sibling I was after (e.g. the link associated with the p). This may work for you:

    def find_link_for_feature(feature_name)
        find(:xpath, "//p[contains(.,'#{feature_name}')]/ancestor::li/descendant::a")
    end
    
    find_link_for_feature('Feature 1').click
    

    You may want to add extra filtering so that it only finds the link with the suggest_btn class, depending on your situation.

    As I mentioned in the comment on the question, however, I much prefer to modify the markup so that it’s actually testable without having to jump through hoops such as these! I consider this kind of XPath to be something of a last resort for when I’m not able to modify the markup.

    EDIT:

    Thinking about your comment asking how to do other things in the scope of the parent element, I’d be more tempted to do something like the following, which gives you more flexibility, and trims down the ugly XPath slightly:

    def find_section_for_feature(feature_name)
        find(:xpath, "//p[contains(.,'#{feature_name}')]/ancestor::li")
    end
    
    within find_section_for_feature('Feature 1') do
        click_link 'Try Now'
        # Anything else you want to do
    and
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML on a Jquery Mobile Page: <div data-role=controlgroup data-type=horizontal class=panelSwitcher>
In the following HTML page, I have a div, which contains two spans (
I have the following elements in a HTML page: <body> <div style=height:100%; width:100%> <div
in my html page, I have the following: <div id=rub> Select at least one
Hey guys, I have the following HTML structure that I am trying to pull
Assuming I have the following ASP.NET HTML Code: <html> <head><title>Test Page</title></head> <body id=bodyID> <asp:Label
I have form on my page that has the following code <form class=form> ...
I have the following script inside a HTML page: <script> function Test(){ alert(i got
I have the following HTML page and the background color for the content is
I have the following HTML on my web page: <input id=htmlEdit type=checkbox/> Once the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.