asus
asus

Reputation: 1759

Puppeteer - string is not a valid XPath expression

Everytime I pass an xpath to my function it returns string is not a valid XPath expression. Why is that?

const searchSelector = '//*table/tbody/tr/td[1]';

const result = await page.evaluate(element => {
      return element.textContent;
    }, await page.$x(searchSelector));

html

Upvotes: 0

Views: 815

Answers (1)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

Because it is not a valid XPath, consider this XPath:

//table/tbody/tr/td[1]

or if you need to rely on class name:

//table[@class = 'classname']/tbody/tr/td[1]

Upvotes: 2

Related Questions