17
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

よく使う Puppeteer の処理

Last updated at Posted at 2018-08-10

https://qiita.com/rh_taro/items/32bb6851303cbc613124
上の記事に追加するような形で。

2018/08/14 更新
(編集リクエスト頂ければクレジットと共に掲載します)

キーボード操作

index.js
await page.focus("#id");
await page.keyboard.down('Shift');
await page.keyboard.press('KeyO');
await page.keyboard.press('KeyK');
await page.keyboard.up('Shift');

要素の座標を取得

index.js
page.offset = async (selector)=>{
    let elem = await page.$(selector);
    return await elem._clickablePoint()
};

//使用例
let offset = await page.offset("#ib");
await page.mouse.click(offset.x,offset.y);

フォームのクリア

index.js
page.clear = async (selector)=>{
    let elem = await page.$(selector);
    await elem.click();
    await elem.focus();
    await elem.click({clickCount: 3});
    await elem.press('Backspace');
};

//使用例
await page.clear("#id");

ラジオボタン選択

クリックの後少し待たないとそのあとの処理がおかしくなる(原因不明)

index.js
page.radio = async (name, val) => {
    this.page.click(name + '[value=\'' + val + '\']');
    await this.page.waitFor(500);
};

//使用例
await page.radio("#id","1");
17
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?