I am using puppeteer for node.js v13.3.1, I am building a bot that will apply to jobs on linkedIn. So far I have the following code.
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
]);
})();
So far the bot is logging in and searching with the SEARCHPARAM just fine, however I am having trouble getting the bot to hit the easy apply button on the job posting. Whenever I target this button I get the id as ember(number) and this number is never the same on different browser windows. I have tried targeting the button by class but node is telling me that it cannot find that selector.
Puppeteer docs for reference docs
Please see this link for more detailed answer:
How to click element in Puppeteer using xPath
const elements = await page.$x('<xPath>')
await elements[0].click()
And your XPath selector should be like this:
const element = await page.$x('//button/span[text()="Easy Apply"]')
Code syntax for:
Button element that contain span element which has text inside "Easy Apply"