0

I need fill data to google ads complaint form, but i have issue with this, complaint form is iframe: enter image description here enter image description here here is my code handle with puppeteer: enter image description here

i try get xpath and type to input, but it not effect.

const { Keyboard } = require('puppeteer');
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');

puppeteer.use(StealthPlugin());


   const lienhe = (await page.$x("/html/body/div[1]/root/div/div[1]/div[2]/div/div[1]/notifications-bar/notification-bar/div/div[2]/div/div[2]/notification-action/div[1]/help-learn-more-button/material-button/div[1]"))[0]
   if (lienhe !== undefined) {
      await lienhe.click();
   }
   await page.waitForTimeout(2000);
   let docthem = (await page.$x('/html/body/div[1]/root/div/div[1]/div[2]/div/div[3]/right-hand-rail/div[2]/focus-trap/div[2]/div/div/div/div/education-section/div[2]/div/article-preview/div/button'))[0];
   if (docthem !== undefined) {
      await docthem.click();
   }
   await page.waitForTimeout(2000);
   const khieunai = (await page.$x("/html/body/div[1]/root/div/div[1]/div[2]/div/div[3]/right-hand-rail/div[2]/focus-trap/div[2]/div/div/article-page/div/article/div/div/div/account-suspension-widget/div/div/div/div[2]/button/span"))[0]
   if (khieunai !== undefined) {
      await khieunai.click();
   }
   await page.waitForTimeout(3000);

   const elementHandle = await page.waitForSelector('iframe');
   const frame = await elementHandle.contentFrame();

   const duongpho = await frame.waitForXPath('/html/body/div[1]/div/div/article/form/div[14]/input');
   await duongpho.type('address');

   const zipcode = await frame.waitForXPath('/html/body/div[1]/div/div/article/form/div[15]/input');
   await zipcode.type('04304');

   const city = await frame.waitForXPath('/html/body/div[1]/div/div/article/form/div[16]/input');
   await city.type('Seathe');

   const country = await frame.waitForXPath('/html/body/div[1]/div/div/article/form/div[17]/select');
   await country.type('US');

   debugger;

   const page2 = await browser.newPage();
   await page2.goto('https://pay.google.com/gp/w/u/0/home/settings/', { waitUntil: 'networkidle2' });
   const address = (await $x('/html/body/div[3]/div[2]/div/div[2]/div[4]/div/div[2]/div[2]/div/div/div[2]/div/div/dl/dd/div[1]/div/div/span[2]'))[0].innerText
   const addressPart = address.split(',');

   debugger
})();
ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • Did you forget your IIFE? Watch out for [timeouts](https://stackoverflow.com/questions/46919013/puppeteer-wait-n-seconds-before-continuing-to-the-next-line/73676564#73676564) and [browser-generated selectors](https://serpapi.com/blog/puppeteer-antipatterns/#misusing-developer-tools-generated-selectors) which are liable to fail. – ggorlen May 21 '23 at 18:52

0 Answers0