How to grab specific values from a list that has primitives

Viewed 36

I am new to JS and have a really annoying problem. I am using a combination of Karate UI (sister of Selenium WebDriver) and JS to write tests for a website.

Scenario: I have a table where I am trying to iteratively go through each row that matches my expected text and grab a particular column value for that row.

The HTML looks like this:

<table class="table">
    <tbody>
        <tr xpath="1">
            <td>
                <a href="link">Write</a> &nbsp;
            </td>
            <td>
                123
            </td>
            <td>
                1.0.1.8
            </td>
            <td>
                TargetProduct1
            </td>
            <td>
                
            </td>
            <td>
                P1
            </td>
            <td>
                10.0
            </td>
            <td>
                en-US
            </td>
            <td>
        </tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
</tbody>
</table>

I am using a native Karate command to grab all values that match my criteria. The problem is, the command often yields a list of primitives. Mine looks something like this:

* def getProduct = scriptAll('//table//tbody//tr', '_.innerText', function(x){ return x.contains('TargetProduct') })

* karate.log(getProduct) //produces the following:
Write  123 1.0.1.8 TargetProduct1       P1 10.0 en-US
Write  4586 1.0.1.3 TargetProduct5      Test2 10.1  en-US
Write  134 1.0.1.1 TargetProduct0       Four2 10.3  en-US
Write  3 1.0.1.2 TargetProduct2     Boo3 10.1   en-US

What I would like to do is, extract sixth column values into an array (P1, Test2, Four2, Boo3). Historically I have been able to grab values using Object.Keys. However, since this is a list, I cannot do Keys. I have tried Object.Values and it also does not work.

Please advise. Thank you in advance!

PS- I already asked the question on the Karate forum and there was no answer, so that is why I am not tagging it here.

0 Answers
Related