async function login(page, username, password) { await page.waitFor('input[id=userId]'); await page.type('input[id=userId]', username); await page.type('input[id=password]', password); await page.click('button[type="submit"]'); await page.waitFor('p.success-msg'); } module.exports = { login }
async function login(page, username, password) { await page.waitFor('input[id=userId]'); await page.type('input[id=userId]', username); await page.type('input[id=password]', password); await page.click('button[type="submit"]'); await page.waitFor('p.success-msg'); } module.exports = { login }
const e = await page.$('#searchResultsSidebar'); const box = await e.boundingBox(); await page.mouse.move(box.x + box.width / 2, box.y + boy.height / 2); await page.mouse.down(); await page.mouse.move(100, 200); // move to (100, 200) coordinates await page.mouse.up();
const e = await page.$('#searchResultsSidebar'); const box = await e.boundingBox(); await page.mouse.move(box.x + box.width / 2, box.y + boy.height / 2); await page.mouse.down(); await page.mouse.move(100, 200); // move to (100, 200) coordinates await page.mouse.up();
const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://example.com/'); const title = await page.$x("//h1"); let text = await page.evaluate(h1 => h1.textContent, title[0]); console.log(text) await browser.close();
await page.click('.link-page-wrap',{ clickCount: 2 }); const foo = await page.$('.foo-item'); await = foo.click(); await = foo.click({ clickCount: 2 });
const browserFetcher = puppeteer.createBrowserFetcher(); const revisionInfo = await browserFetcher.download('533271'); const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath})
await page.evaluate(() => { document.querySelector('mySelector').style.display = 'yes'; });
const puppeteer = require('puppeteer'); ;(async () => { const browser = await puppeteer.launch({headless: false}) const page = await browser.newPage() await page.goto('https://archive.kbb1.com/lessons', {waitUntil: 'networkidle2'}); // Clicking on Date filter // Click Apply and check if filter tag is created await Promise.all([ await page.click(".ui.blue.large.pointing.secondary.index-filters.menu div a:nth-child(4)"), page.waitForSelector("div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(2) > div > input") ]); await page.$eval("div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(1) > div > input[type=\"text\"]", (selector) => { selector.value = ""; }); await page.$eval(".class", (selector) => { selector.value = ""; }); })()
const searchValue = await page.$eval('#search', el => el.value); const preloadHref = await page.$eval('link[rel=preload]', el => el.href); const text = await page.$eval('.text', el => el.textContent); const html = await page.$eval('.main-container', e => e.outerHTML);
const textArray = await page.$$eval('.text', els => Array.from(els).map(el=> el.textContent));
beforeAll(async () => { browser = await puppeteer.launch({ headless: false, slowMo: 80 }); page = await browser.newPage(); }); afterAll(()=> { browser.close(); });
toBeGreaterThan(number): 大於html
toBeLessThan(number): 小於json
4.not 取反,用法見下面例子數組
var str = "{' retmsg':'success ',\n' trans_date':' 20170906'}"; console.log(str); //"{' retmsg':'success ', //' trans_date':' 20170906'}"
str = str.replace(/\ +/g,""); console.log(str); //"{'retmsg':'success', //'trans_date':'20170906'}"
str = str.replace(/[\r\n]/g,""); console.log(str); //"{'retmsg':'success','trans_date':'20170906'}"