1
1

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.

Robot FrameworkでURLリストを読んでスクリーンショットをとりまくる

Posted at

調べてもなかなか出てこなかったのでメモ。
(もっといい方法があればどなたか教えてください)

  • URLリストを外部ファイル(list.tsv)から読み込んで
  • それらに対してスクリーンショットを撮る
  • フルページで撮る
  • pythonの変数に行を突っ込んで回してます
screen_shot.robot
*** Settings ***
Library    SeleniumLibrary
Variables   ./import.py

*** Keywords ***
Create Chrome Driver
	${options} =  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys
	Call method  ${options}  add_argument    --headless
	Create webdriver    Chrome    chrome_options=${options}

*** Test Cases ***
キーワード
	Create Chrome Driver
    ${w} =    Execute JavaScript    return document.body.scrollWidth
    ${h} =    Execute JavaScript    return document.body.scrollHeight
    Set Window Size  ${w}  ${h}
    Set ScreenShot Directory    path=screenshot

    ${length}=  Get Length  ${conditions}
    :FOR    ${idx}  IN RANGE    ${length}
    \   Go To    @{urls}[${idx}]
    \   Capture Page Screenshot     filename=@{conditions}[${idx}].png
import.py
import csv

with open('list.tsv') as f:
    reader = csv.reader(f, delimiter='\t')
    l = [row for row in reader]
    l_T = [list(x) for x in zip(*l)]
    conditions = l_T[0]
    urls = l_T[1]
list.tsv
ねこ https://www.google.com/search?q=%E3%81%AD%E3%81%93&tbm=isch
いぬ https://www.google.com/search?q=%E3%81%84%E3%81%AC&tbm=isch
さる https://www.google.com/search?q=%E3%81%95%E3%82%8B&tbm=isch
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?