1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "browser.start": "https://www.wikipedia.org",
12 "browser.engine": "chromium",
13 "script":
14
15
16
17
18
19 context => async ({page, tools: {sleep, expect, waitForPage}} = context) => {
20
21 page.setDefaultNavigationTimeout(90 * 1000);
22
23 await page.goto('https://www.wikipedia.org/', {waitUntil: 'domcontentloaded'});
24 await page.getByRole('button', { name: 'Read Wikipedia in your' }).click();
25 await page.getByRole('searchbox', { name: 'Search Wikipedia' }).click();
26 await page.getByRole('searchbox', { name: 'Search Wikipedia' }).fill('hello world');
27 await page.getByRole('searchbox', { name: 'Search Wikipedia' }).press('ArrowDown');
28 await page.getByRole('searchbox', { name: 'Search Wikipedia' }).press('Enter');
29 await page.getByRole('link', { name: 'View history' }).click();
30 await page.getByRole('button', { name: 'Compare selected revisions' }).first().click();
31 await page.getByRole('switch', { name: 'Inline' }).click();
32 await page.getByRole('button', { name: 'Visual' }).click();
33 await page.getByRole('button', { name: 'Tools' }).check();
34 await page.getByRole('link', { name: 'Edit', exact: true }).click();
35
36 await page.goto('https://apify.com/store/', {waitUntil: 'domcontentloaded'});
37 await page.getByRole('combobox').click();
38 await page.locator('[data-test="actor-store-search"]').click();
39 await page.locator('[data-test="actor-store-search"]').fill('chrome extensions');
40 await page.locator('[data-test="actor-store-search"]').press('ArrowDown');
41 await page.locator('[data-test="actor-store-search"]').press('ArrowDown');
42 await page.locator('[data-test="actor-store-search"]').press('ArrowUp');
43 await page.locator('[data-test="actor-store-search"]').press('ArrowUp');
44 await page.locator('[data-test="actor-store-search"]').press('Enter');
45 await page.locator('[data-test="store-filter-category"]').click();
46 await page.locator('[data-test="store-filter-category"]').press('Tab');
47 await page.locator('[data-test="store-filter-pricing"]').press('Tab');
48 await page.locator('[data-test="store-filter-managedBy"]').press('ArrowDown');
49 await page.getByRole('option', { name: 'All developers' }).press('ArrowDown');
50 await page.getByRole('option', { name: 'Maintained by Apify' }).press('ArrowDown');
51 await page.getByRole('option', { name: 'Maintained by Community' }).press('Enter');
52 await page.getByRole('link', { name: 'Chrome Extensions avatar' }).click();
53 await page.getByRole('tab', { name: 'Input' }).click();
54 await page.getByRole('tab', { name: 'API' }).click();
55 await page.getByRole('tab', { name: 'Reviews' }).click();
56 await page.getByRole('link', { name: 'Vasek Codey Vlcek Vasek Codey' }).click();
57 await page.locator('div').filter({ hasText: 'Vasek Codey' }).nth(2).click();
58
59 return {
60 example: true,
61 success: true,
62 };
63 };
64
65
66
67 ,
68 "custom": {
69 "example": "input to be used in the script"
70 },
71 "proxy": {
72 "useApifyProxy": false
73 }
74};
75
76
77const run = await client.actor("cyberfly/apify-agent").call(input);
78
79
80console.log('Results from dataset');
81console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
82const { items } = await client.dataset(run.defaultDatasetId).listItems();
83items.forEach((item) => {
84 console.dir(item);
85});
86
87