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.

【Selenium】手動で行った動作を記録して、何度も実行させたい

Posted at

Motivation

社内向けシステムの品質が悪く、何度も何度もクリック・キーボード操作をさせるGUIがあまり得意ではない

ということで、ブラウザで行う動作をSeleniumを用いて半自動化したい
ただ、いきなりSeleniumAPIをばしばし叩くのも、ハードルが高いと思ったので
行った操作をスクリプト化できたらいいな、という発想

導入

Firefox向けSeleniumプラグイン: Selenium IDE
下記画面が表示されるので、「Firefoxへ追加」を押下

Screen Shot 2018-06-10 at 1.33.45.png

使ってみた(GIF)

test2.gif

JSON形式で操作一覧が出力される

commandsってところが、実行している操作の一覧みたい
pythonとかnodejs用にexportできればいいのだけど

output.json
{
    "id": "702a91c3-409c-4014-afe4-9b6686858cb1",
    "name": "test_selenium",
    "suites": [
        {
            "id": "3522401c-a5eb-480f-8d61-a8671251c4c3",
            "name": "Default Suite",
            "tests": [
                "de2effc2-81c4-438c-b6f1-266d97ec6ed1"
            ]
        }
    ],
    "tests": [
        {
            "commands": [
                {
                    "command": "open",
                    "comment": "",
                    "id": "3fa1e5dd-51a6-4fe7-b76e-65e8d66b15e6",
                    "target": "/search",
                    "value": ""
                },
                {
                    "command": "type",
                    "comment": "",
                    "id": "d08aa09d-ab8d-49af-b50c-c290e5952fc5",
                    "target": "id=lst-ib",
                    "value": "qiita"
                },
                {
                    "command": "sendKeys",
                    "comment": "",
                    "id": "2d530f8a-0158-4016-b2ef-ac236f742e6b",
                    "target": "id=lst-ib",
                    "value": "${KEY_ENTER}"
                },
                {
                    "command": "clickAt",
                    "comment": "",
                    "id": "a81db28d-4209-412c-a51b-6a270cdd24c1",
                    "target": "css=h3.r > a",
                    "value": "18,13"
                },
                {
                    "command": "mouseOver",
                    "comment": "",
                    "id": "8215a23a-9504-4ed1-856a-90f796ce0999",
                    "target": "css=h3.r > a",
                    "value": ""
                }
            ],
            "id": "de2effc2-81c4-438c-b6f1-266d97ec6ed1",
            "name": "Untitled"
        }
    ],
    "url": "https://www.google.com",
    "urls": [
        "https://www.google.com"
    ]
}

まとめ

Seleniumで自動化する際に、要素のIDとか気にせず直感的に操作を吐き出せるのは◎
ただし、この記事を書くために使用した際に、操作を取得できないことが頻発した
それも歯抜けで取得はできるから、途中の操作がなくて結局次の操作につながらないことがあった

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?