Nasir Ahemad
Nasir Ahemad

Reputation: 3

How to get URL present inside div attribute?

<div data-url="https://latestVersionInfo/android/download/">
1.1.0 <span>Nov 10th, 2020</span>
</div>

I tried with this:

const ver = await page.$('div#versions-items-list.content div');
const versionUrl = await (await ver.getProperty('data-url')).jsonValue();

but its not working.!! Output String is displayed as "undefined"

Upvotes: 0

Views: 63

Answers (1)

yeniv
yeniv

Reputation: 1639

One of the option is to use the page.$eval API to exercise some code in context of the page and get this attribute value.

const dataurl = await page.$eval('div#versions-items-list.content div', el => el.getAttribute('data-url'));
console.log("dataurl:", dataurl);

Upvotes: 1

Related Questions