OSAMA E
OSAMA E

Reputation: 341

Selenium get access to text using css

I am trying to access text of table data using Selenium and then checking if it is equal to given text.

The problem I am facing is Expected result gets converted to Array with [] brackets.

How can I convert this to basic string? What code change will help me achieve this?

Below is my code

const resultList = element.all(by.css('table tr:nth-of-type(9) [colspan]')); 
expect(resultList.getText()).toEqual("This is data"); 

Output - Error

Expected [ 'This is data' ] to equal 'This is data'. 

Trying to achieve (Without Brackets [])

Expected  'This is data'  to equal 'This is data'. 

Upvotes: 2

Views: 54

Answers (1)

Ashish Shah
Ashish Shah

Reputation: 1132

You can change your code to this -

expect(element(by.css('table tr:nth-of-type(9) [colspan]')).getText()).toEqual("This is test data.");

Upvotes: 1

Related Questions