OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to select elements within an iframe element in Puppeteer

  • Thread starter Thread starter SwapnikK
  • Start date Start date
S

SwapnikK

Guest
Since ESPN does not provide an API, I am trying to use Puppeteer to scrape data about my fantasy football league. However, I am having a hard time trying to login using puppeteer due to the login form being nested with an iframe element.

I have gone to http://www.espn.com/login and selected the iframe. I can't seem to select any of the elements within the iframe except for the main section by doing

Code:
frame.$('.main')

This is the code that seems to get the iframe with the login form.

Code:
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();

await page.goto('http://www.espn.com/login')
await page.waitForSelector("iframe");

const elementHandle = await page.$('div#disneyid-wrapper iframe');
const frame = await elementHandle.contentFrame();
await browser.close()

I want to be able to access the username field, password field, and the login button within the iframe element. Whenever I try to access these fields, I get a return of null.

<p>Since ESPN does not provide an API, I am trying to use Puppeteer to scrape data about my fantasy football league. However, I am having a hard time trying to login using puppeteer due to the login form being nested with an iframe element.</p>
<p>I have gone to <a href="http://www.espn.com/login" rel="nofollow noreferrer">http://www.espn.com/login</a> and selected the iframe. I can't seem to select any of the elements within the iframe except for the main section by doing</p>
<pre class="lang-js prettyprint-override"><code>frame.$('.main')
</code></pre>
<p>This is the code that seems to get the iframe with the login form.</p>
<pre class="lang-js prettyprint-override"><code>const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();

await page.goto('http://www.espn.com/login')
await page.waitForSelector("iframe");

const elementHandle = await page.$('div#disneyid-wrapper iframe');
const frame = await elementHandle.contentFrame();
await browser.close()
</code></pre>
<p>I want to be able to access the username field, password field, and the login button within the iframe element. Whenever I try to access these fields, I get a return of null.</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top