Vinee
Vinee

Reputation: 402

webdriverio findelements and $$ options are returning a Typescript error getText is not a function

I have the below html tag generated as part of highchart

<g class="highcharts-axis-labels highcharts-xaxis-labels " data-z-index="7">
<text x="332.3333333333367" style="color:#666666;cursor:default;font-size:13;fill:#666666;" text-anchor="middle" transform="translate(0,0)" y="246" opacity="1">60</text>
<text x="886.9999999999668" style="color:#666666;cursor:default;font-size:13;fill:#666666;" text-anchor="middle" transform="translate(0,0)" y="246" opacity="1">65</text>
<text x="1441.6666666666667" style="color:#666666;cursor:default;font-size:13;fill:#666666;" text-anchor="middle" transform="translate(0,0)" y="246" opacity="1">70</text>
</g>

I am trying to extract all the text values in it and used the below command

xAxis =  $('.highcharts-xaxis-labels').$$('text').getText();

I tried the browser.findelements using the XPATH as well. But with both I am getting the error message

TypeError: $(...).$$(...).getText is not a function

Upvotes: 1

Views: 2092

Answers (1)

Stephan Muller
Stephan Muller

Reputation: 27600

The problem here is that $$ (an alias for getElements) returns an array of elements, not just one element. An element has a getText() method, but an array doesn't have that.

If you want to get a list of all the values, you need to map the list of elements to each element's value:

$('.highcharts-xaxis-labels').$$('text').map(textElement => textElement.getText());

Upvotes: 1

Related Questions