やりたいこと
・Selenium IDEでPython pytestとして exportしたコードをPythonで動かしたいです。
現在の状況
・Selenium自体は動いていて、以下URLの(google-search.pyというファイルの確認コード)をコピペしたらChromeが無事起動し、やりたい処理を行えました。
・しかし、Selenium IDEでexportして生成したコードをコピペして実行してみても何も起動しません。何か手を加える必要があるのでしょうか?
現状の例:
ChromeでGoogleを開き、「selenium」と検索し、一番上に出てきたサイトをクリックし、その中の「WebDriverを始めよう」という欄をクリックするというシンプルな工程をselenium IDEで録画し、exportしたところ以下のコードが表示されました。しかし、自分でseleniumを用いて簡単な処理をした場合はちゃんと動くのに、Selenium IDEで生成したシンプルな処理のコードをコピペしても動きません。実行しても何も起こらないです。これを動かすにはどうしたらいいか教えてほしいです。この処理自体を行いたいのではなく、Selenium IDEで生成したコードをPythonで使う方法を教えてほしいです。初歩的な質問で申し訳ございません。
Python
1 2# Generated by Selenium IDE 3import pytest 4import time 5import json 6from selenium import webdriver 7from selenium.webdriver.common.by import By 8from selenium.webdriver.common.action_chains import ActionChains 9from selenium.webdriver.support import expected_conditions 10from selenium.webdriver.support.wait import WebDriverWait 11from selenium.webdriver.common.keys import Keys 12from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 13 14class TestTest1(): 15 def setup_method(self, method): 16 self.driver = webdriver.Chrome() 17 self.vars = {} 18 19 def teardown_method(self, method): 20 self.driver.quit() 21 22 def test_test1(self): 23 self.driver.get("https://www.google.com/?hl=ja") 24 self.driver.set_window_size(1118, 760) 25 self.driver.find_element(By.NAME, "q").send_keys("sele") 26 self.driver.find_element(By.CSS_SELECTOR, ".sbhl .wM6W7d > span").click() 27 self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(2) > .tF2Cxc .LC20lb").click() 28 self.driver.find_element(By.LINK_TEXT, "WebDriverをはじめよう").click() 29
あなたの回答
tips
プレビュー