Reputation: 1001
I am new to GEB and using jQuery.
I am trying to select or to find if a child of an element deeper n levels with specific text.
I am trying to use the contains selector but is not working as i was expecting.
Simple example:
...
<div class="widget-header-title">My Tasks</div>
...
I am trying to execute this selector
$('div:contains("My Tasks")')
but i am getting an exception:
Method threw 'org.openqa.selenium.InvalidSelectorException' exception.
What i really need to do is check if a child element of another contains text
<div id="taskLegend">
<div>
....
<text ....>Call</text>
....
</div>
</div>
I tried this selector and i get the same exception above
$("#taskLegend").find("text:contains('Call')")
but using
$("#taskLegend").find("text")
it return all the elements "text" inside taskLegend
looks like is the contains that is not working.
Can someone spot what I am doing wrong?
Thank you so much
Upvotes: 0
Views: 148
Reputation: 597
Not that the first answer is wrong, but another way to do this is by passing a By
object into you Jquery closure https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html
So for me personally I would probably use xpath (although note xpath is technically the slowest)
so it would look something like this:
$(By.xpath("//div[contains(text(), 'My Tasks')]"))
This will return all divs that contain text 'My Tasks'
Upvotes: 2
Reputation: 332
the quotations are for the element and its tags (ex. "h1.class")
if you wish to search using text:contains it needs to be in this format:
$("#taskLegend").find("text", text:contains("Call"))
the word "text" in your case has 2 meanings; a text element itself and the text of an element
Upvotes: 1