Last active
August 10, 2019 07:13
-
-
Save gologius/24d2dfa8957bc172ceb75fdc75fd0e59 to your computer and use it in GitHub Desktop.
Selenium(Python)でフレームレイアウトのサイトを自動操作するサンプルです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sat Mar 9 16:28:14 2019 | |
@author: gologius | |
""" | |
from selenium import webdriver | |
import time | |
CHROME_DRIVER_PATH = "chromedriver_win32\chromedriver.exe" | |
URL = "https://gologius.github.io/test/selenium_lecture_3.html" | |
driver = webdriver.Chrome(CHROME_DRIVER_PATH) | |
driver.implicitly_wait(10) #sec | |
WAIT_TIME = 1 | |
""" | |
フレームレイアウトサイト構造 | |
selenium_lecture_3.html | |
<frame_leftup.html" name="frame_leftup" title="左上フレーム"> | |
<frame_leftdown.html" name="frame_leftdown" title="左下フレーム"> | |
<frame_right.html" name="frame_right" title="右フレーム"> | |
""" | |
def process(): | |
""" | |
シンプルな要素選択 | |
""" | |
driver.get(URL) | |
#フレーム左下を選択 | |
frame = driver.find_element_by_name("frame_leftdown") | |
driver.switch_to_frame(frame) | |
#要素を指定→クリック | |
elm = driver.find_element_by_link_text("右メニューを1に変更") | |
elm.click() | |
time.sleep(WAIT_TIME) | |
print("右1") | |
#要素を指定→クリック | |
elm = driver.find_element_by_link_text("右メニューを2に変更") | |
elm.click() | |
time.sleep(WAIT_TIME) | |
print("右2") | |
#要素を指定→クリック | |
elm = driver.find_element_by_link_text("左上メニューを1に変更") | |
elm.click() | |
time.sleep(WAIT_TIME) | |
print("左1") | |
#要素を指定→クリック | |
elm = driver.find_element_by_link_text("左上メニューを2に変更") | |
elm.click() | |
time.sleep(WAIT_TIME) | |
print("左2") | |
return | |
process() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment