0

I am trying to test a page generated by a .gsp file. For that I need to access the text value of a specific field. The generated HTML looks like this:

<dt>
<label class="control-label" for="isPublic">Public?</label>
</dt>
<dd> No </dd>

The gsp generating that looks like this:

<dl>
    <dt><label class="control-label" for="isPublic">Public?</label></dt>
    <dd> <g:xEditableRefData owner="${license}" field="isPublic" config='YN'/>
        </dd>
/dl>

In the scenario I am trying to test, the g:editableRefData is disabled, so the first HTML code is what I am looking at.

I have tried to access it using code like:

        def par = $("label",for:'isPublic').parent().siblings().find("dd").value()
        def par =  $("label",for:'isPublic').parent().nextSibling().value()

Also tried to grab just the label with $("label",text:'Public?').value() but it it returns null.

I have tried replacing .value() with .@text . I have tried removing the g:xEditableRefData and hardcoding 'No' but that didnt change anything. There are a number of tests working as expected before this one. Are there any suggestions on how to get the text inside 'dd' tags?

UPDATE I was selecting the text wrong, I had to use .text() .

Giannis
  • 5,286
  • 15
  • 58
  • 113

1 Answers1

1

If your selector is working, then text() is what you need. For example:

assert $("label", for: "isPublic").parent().next().text() == "No"

I'm not a css selector expert, so there's probably a better way.

Ken
  • 685
  • 2
  • 5
  • 11