1

I am using JMeter and I want to extract from a response the value of a column from a row which contains a certain value :

Concretely I want to get the row which contains 677777 and for that row to get the column dv-col dv-col-type-enum dv-col-task-state which in this specific case is Open.

Tried several regexps but no success yet,so any help or clue is welcome.

<!DOCTYPE html>
<html lang="en">
    <head></head>
    <body class="bootstrap env-dlt">
        <div id="main-container" class="container-fluid">
            <div id="main-header" class="header"></div>
            <div class="section">
                <div class="dv-filters large-content"></div>
                <div class="dv-container large-content">
                    <table class="table table-striped table-bordered table-condensed">
                        <thead></thead>
                        <tbody class="taskList">
                            <tr>..</tr>
                            <tr>..</tr>
                            <tr>..</tr>
                            <tr>
                                <td class="dv-col dv-col-type-string dv-col-task-panel"></td>
                                <td class="dv-col dv-col-type-string dv-col-task-phase"></td>
                                <td class="dv-col dv-col-type-long dv-col-task-proposal_reference">
                                    <a href="/presentation/workflow/tasks/111111/detail.html">
                                        677777
                                    </a>
                                </td>
                                <td class="dv-col dv-col-type-long dv-col-task-proposal_acronym"></td>
                                <td class="dv-col dv-col-type-enum dv-col-task-state">
                                    Open
                                </td>
                                <td class="dv-col dv-col-type-long dv-col-task-owner"></td>
                                <td class="dv-col dv-col-type-date dv-col-task-deadline"></td>
                                <td class="dv-col dv-col-type-double dv-col-task-score"></td>
                                <td class="dv-col dv-col-type-action"></td>
                            </tr>
                            <tr>..</tr>
                            <tr>..</tr>
                            <tr>..</tr>

Xpath might be an alternative ?

Thanks

Cris
  • 4,947
  • 6
  • 44
  • 73
  • 3
    You should use xpath. Parsing HTML with regex is always a headache: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – mhlz Mar 03 '15 at 16:13
  • did not know about that thread, however my feeling was as well that is more suitable for xpath. – Cris Mar 03 '15 at 21:02

2 Answers2

3

the xpath for getting the desire result is:

//tr[td/a[contains(text(),"677777")]]/td[@class="dv-col dv-col-type-enum dv-col-task-state"]/text()

first find the <tr> that contains a <td> which has an <a>'s text() contains, or equal to 677777, then find the <td> tab which class is "dv-col dv-col-type-enum dv-col-task-state" under the target <tr>

kaho
  • 4,746
  • 1
  • 16
  • 24
2

I want to get the row which contains 677777

Using XPath (selects the entire row node):

//tr[*=677777]

To get the column data testing for the contents of the @classattribute:

//tr[*=677777]/td[@class[contains(.,"dv-col-task-state") and contains(.,"dv-col-type-enum") ]]

(Assuming you don't have or don't care about matching classes which include those class names. Ex: dv-col-task-state-something. If that's a concern, you need to concatenate and match the white-space in the class attribute to assure they represent individual class names)

helderdarocha
  • 23,209
  • 4
  • 50
  • 65