I am trying to automate an export process for notion.so. I am a complete novice in puppeteer and ui-automation frameworks in general so any help is appreciated. In the following pop-up I want to click on "current view" make a choice there and then click on "export"
This is what I have tried so far.
const puppeteer = require('puppeteer');
const path = require('path');
(async () => {
const browser = await puppeteer.launch({headless :false});
const page = await browser.newPage();
// Set screen size
await page.setViewport({width: 1920, height: 1080});
await page.goto('https://www.notion.so/');
await page.waitForSelector('text/Log in');
await page.click('text/Log in');
const emailInput = await page.waitForSelector('#notion-email-input-1');
await emailInput.type("mymail");
await page.click('text/Continue with email');
await page.waitForSelector('#notion-password-input-2');
await page.type('#notion-password-input-2', 'mypass');
const passwordButton = await page.waitForSelector('text/Continue with password');
await passwordButton.click();
const moreButton = await page.waitForSelector('div.notion-topbar-more-button');
await moreButton.click();
const exportButton = await page.waitForSelector('text/Export');
await exportButton.click();
// this works well untill this point
// beyond this point it seems like I can't interact with the elemens in the popup
//Below are some attempts to get the elements using XPath or other methods. None of them work.
const databaseListView = await
page.waitForXPath('/html/body/div[1]/div/div[2]/div[2]/div/div[2]/div/div[2]/div[2]');
await databaseListView.click();
const everythingOption = await page.waitForSelector('#id_86>div>div>div');
await everythingOption.click();
const finalExportButton = await page.waitForXPath('//*[@id="notion-
app"]/div/div[2]/div[2]/div/div[2]/div/div[6]/div[2]');
await finalExportButton.click();
await delay(15000);
await browser.close();
})();
function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time)
});
}
What can I do to interact with these elements?
try below with updated locators, i was able to click on elements with below script, just updated the locators for popup
const puppeteer = require('puppeteer');
const path = require('path');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// Set screen size
await page.setViewport({ width: 1920, height: 1080 });
await page.goto('https://www.notion.so/');
await page.waitForSelector('text/Log in');
await page.click('text/Log in');
const emailInput = await page.waitForSelector('#notion-email-input-1');
await emailInput.type("user");
await page.click('text/Continue with email');
await page.waitForSelector('#notion-password-input-2');
await page.type('#notion-password-input-2', 'pass');
const passwordButton = await page.waitForSelector('text/Continue with password');
await passwordButton.click();
const moreButton = await page.waitForSelector('div.notion-topbar-more-button');
await moreButton.click();
const exportButton = await page.waitForSelector('text/Export');
await exportButton.click();
// this works well untill this point
// beyond this point it seems like I can't interact with the elemens in the popup
//Below are some attempts to get the elements using XPath or other methods. None of them work.
const databaseListView = await
page.waitForXPath('//div[normalize-space()=\'Current view\']');
await databaseListView.click();
const everythingOption = await page.waitForXPath('(//div[normalize-space()="Everything"])[2]');
await everythingOption.click();
await page.evaluate(() => {
const finalExportButton = document.evaluate('//div[@role="button" and text()="Export"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
finalExportButton.click();
});
await delay(15000);
await browser.close();
})();
function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time)
});
}