Skip to content

Instantly share code, notes, and snippets.

@kurozumi kurozumi/cancel-program.py

Last active Feb 14, 2016
Embed
What would you like to do?
【Python】Seleniumを使ってA8.netのプログラム契約解除を自動化する
# coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.alert import Alert
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("http://www.a8.net")
username = driver.find_element_by_name("login")
username.send_keys("username")
password = driver.find_element_by_name("passwd")
password.send_keys("password")
button = driver.find_element_by_name("lgin_as_btn")
button.click()
while True:
try:
# プログラム管理をクリック
menu = driver.find_element_by_css_selector("#globalMenuWrap")
submenu = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/ul/li[3]/ul/li[1]/a");
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(submenu)
actions.perform()
#プログラム詳細ボタンクリック
button = driver.find_element_by_xpath("/html/body/div[2]/div/div/form[2]/div/div[2]/div[3]/table[1]/tbody/tr[1]/td[6]/table/tbody/tr[2]/td/a");
button.click()
#契約解除メニュークリック
button = driver.find_element_by_xpath("/html/body/div[2]/div/div/div/div/div/ul/li[4]/a");
button.click()
#契約解除ボタンクリック
button = driver.find_element_by_xpath("/html/body/div[2]/div/div/form/div/div[2]/a");
button.click()
#契約解除に同意する
Alert(driver).accept()
#トップへ戻る
button = driver.find_element_by_xpath("/html/body/div[3]/a");
button.click()
except:
driver.close()
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.