Skip to content

Instantly share code, notes, and snippets.

@hogelog
Created March 18, 2023 04:55
Show Gist options
  • Save hogelog/8169ac693fbb03f067bbb81519e22643 to your computer and use it in GitHub Desktop.
Save hogelog/8169ac693fbb03f067bbb81519e22643 to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const context = browser.defaultBrowserContext();
await context.overridePermissions('https://stretch3.github.io', ['camera', 'microphone']);
const page = (await browser.pages())[0];
await page.goto('https://stretch3.github.io/');
const uploadfile = '/home/pi/robot/scratch3-autostart/main.sb3';
const fileMenu = (await page.$x("//*[contains(text(), 'ファイル')]"))[0];
await fileMenu.click()
const loadMenu = (await page.$x("//*[contains(text(), 'コンピューターから読み込む')]"))[0];
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
loadMenu.click(),
]);
await fileChooser.accept([uploadfile]);
await page.bringToFront();
await page.waitForTimeout(2000);
const executeButton = await page.$('[title="実行"]');
await executeButton.click();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment