Estoy usando titiritero para node.js v13.3.1, estoy creando un bot que se aplicará a trabajos en linkedIn. Hasta ahora tengo el siguiente código.
const puppeteer = require('puppeteer'); const SEARCHPARAM = "react" // change this for search param require("dotenv").config(); (async () => { const browser = await puppeteer.launch({headless:false}); const page = await browser.newPage(); await page.goto('https://www.linkedin.com/login?fromSignIn=true&trk=guest_homepage-basic_nav-header-signin') await page.setViewport({ width: 1920, height: 1080}); await page.type("#username", process.env.NAMEUSERNAME) await page.type("#password", process.env.PASSWORD) await page.click('button[type="submit"]') //works fine await Promise.all([ await page.waitForNavigation(), await page.click('#global-nav > div > nav > ul > li:nth-child(3)'), await page.type('input', SEARCHPARAM ), await page.click('button[type="button"]'), await page.click('#ember1052 > span') //Will not hit the button ]); })(); Hasta ahora, el bot está iniciando sesión y buscando con SEARCHPARAM sin problemas, sin embargo, tengo problemas para que el bot presione el botón de easy apply en la publicación de trabajo. Cada vez que apunto este botón, obtengo la identificación como ember (número) y este número nunca es el mismo en diferentes ventanas del navegador. Intenté apuntar al botón por clase, pero el nodo me dice que no puede encontrar ese selector.
Documentos de titiriteros para documentos de referencia
Consulte este enlace para obtener una respuesta más detallada:
Cómo hacer clic en el elemento en Puppeteer usando xPath
const elements = await page.$x('<xPath>') await elements[0].click()Y su selector XPath debería ser así:
const element = await page.$x('//button/span[text()="Easy Apply"]') Sintaxis de código para:
Button element that contain span element which has text inside "Easy Apply"