skadabr / puppeteer-selector Goto Github PK
View Code? Open in Web Editor NEWadvanced css selectors for puppeteer
License: MIT License
advanced css selectors for puppeteer
License: MIT License
@Skadabr good stuff this is. ๐
Can't you make this to return multiple elements rather than the first element? :contains()
may result in multiple elements rather than a single element.
Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: ReferenceError: Sizzle is not defined
Package.json:
"puppeteer": "^1.19.0", "puppeteer-select": "^1.0.3",
Platform/OS: Windows 10
Node Js version 8.9.1
const puppeteer = require('puppeteer');
const select = require ('puppeteer-select');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('somesite');
await select(page).assertElementPresent('span:contains("someText")');
const element = await select(page).getElement('span:contains("someText")');
await element.click()
await browser.close();
})();
Hey! First of all thank you for this, i'm trying to use it in one of my projects and so far is working great.
But today i tried to find a div by the text inside of it (i can't use the id, the class or the name of the div), but it doesn't work.
What i tried is
await select(page).assertElementPresent('div:contains(Text) > "hello"');
const element = await select(page).getElement('div:contains(Text) > "hello"');
await element.click()
if you can help me with this it will be awesome.
Thank you
Step To Reproduce
Tell us about your environment:
"puppeteer": "^1.17.0", "puppeteer-select": "^1.0.2"
What steps will reproduce the problem?
i have for loop, inside of it select element that contains text (pagination). Sometimes it cant find the element and throw error like this :
Error: an element with selector: "a.page_promo_lain:contains(undefined)" not found
my for loop code :
`for (let activePage of pages) {
console.log('page sekarang ' + activePage)
await page.waitFor(2000)
let clickPage = await select(page).getElement(`a.page_promo_lain:contains(${activePage})`)
await clickPage.click()
// if promo exist
if (await page.$('#imgClass') !== null) {
// get href promo
const hrefs = await page.evaluate(
() => Array.from(document.body.querySelectorAll('#promolain > li > a'), ({ href }) => href)
);
for (let href of hrefs) {
const detail = await getDetails(browser, href)
result[`${cat}`].push(detail);
}
} else {
console.log('Promo not found!');
}
}`
What is the expected result?
should be able to click element
What happens instead?
cant find element
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.