After the first few weeks of overtime, overtime applications should mention it again every day, feeling very complicated, think of writing an automated application submitted overtime timing tasks. And then automatically submit work overtime to finish this part of the application, I feel there are several distinct points, so posted record over it. Because it is an internal company system, so the link does not work, so the addresses and users with "XXX" in place!
from selenium import webdriver driver=webdriver.Chrome() driver.get("http://xxxxxxx/") driver.maximize_window() driver.find_element_by_css_selector('[name="UserID"]').send_keys(xxx) driver.find_element_by_css_selector('[name="Passwrd"]').send_keys('xxxx') driver.find_element_by_css_selector('[value="登录"]').click() driver.find_element_by_css_selector('[href="javascript:portal()"]') .click () frameElement = driver.find_element_by_css_selector ( ' #main ' ) driver.switch_to.frame (frameElement) # iframes Jump Import Time the time.sleep ( . 5 ) JS = " document.getElementById ( 'sidebar_L'). style. = width '300px by'; document.getElementById ( 'sidebar_L') style.heigth = '300px by';. " driver.execute_script (JS) # high div, the width of 0, in order to obtain the required modifications to the underlying element of time. SLEEP (. 5 ) driver.find_element_by_xpath ( ' // div [@ ID = "sidebar_L"] / div [@ class = "mokuai15 rsg5"] ' ).the Click () # suddenly saw the convenience of getting the location of xpath the time.sleep (. 5 ) driver.find_element_by_xpath ( ' / HTML / body / form / Table / tbody / TR [. 5] / TD [2] / INPUT ' ) .click () the time.sleep ( . 5 ) frameElement1 = driver.find_element_by_xpath ( ' / HTML / body / div / iframe ' ) driver.switch_to.frame (frameElement1) # and need to jump to a iframe, the iframe no id, no name, so use xpath positioned driver.find_element_by_xpath ( ' // * [@ ID = "dpTodayInput"] ' ) .click () driver.switch_to.parent_frame () # require a jump back iframes the time.sleep (. 5 ) JS = "document.getElementById('st_gl0').parentElement.children[13].children[3].children[0].children[7].children[1].children[0].value='19:30'" driver.execute_script(js)#input框内的默认值需要先删除再修改,所以直接用js给修改了。 time.sleep(5) js="document.getElementById('st_gl0').parentElement.children[13].children[3].children[0].children[8].children[1].children[0].value='21:00'" driver.execute_script(js) time.sleep(5) js="document.getElementById('st_gl0').parentElement.children[13].children[3].children[0].children[9].children[1].children[0].value='1.5'" driver.execute_script(js) the time.sleep (5) driver.find_element_by_xpath ( ' / HTML / body / form / Table / tbody / TR [16] / TD [2] / SELECT / Option [2] ' ) .click () # SELECT mode may be positioned css, but more convenient xpath , on the use of XPath the time.sleep (. 5 ) driver.find_element_by_xpath ( ' / HTML / body / form / Table / tbody / TR [25] / TD [2] / INPUT ' ) .click () driver.switch_to.alert. Accept () # alert pop treatment of
the time.sleep ( . 5 )
driver.quit ()
Automatic recharge example:
from selenium import webdriver driver = webdriver.Chrome() driver.get('http://XXXXXX') driver.maximize_window() driver.find_element_by_css_selector('[name="name"]').send_keys('XXXXX') driver.find_element_by_css_selector('[name="passwd"]').send_keys('XXXX') driver.find_element_by_css_selector('[onclick="check_login()"]').click() driver.find_element_by_css_selector('span[style="line-height:100%;"]').click() driver.find_element_by_css_selector('[href="/?system_id=3"]').click() driver.find_element_by_css_selector('[href="/tree?parent_id=1006"]').click() js = "document.getElementById('leftside').style.width = '500px';document.getElementById('leftside').style.heigth = '500px';" driver.execute_script(js) import time time.sleep(1) driver.find_element_by_css_selector('.cur>div>a[rel="rbplist"]').click() from selenium.webdriver.support.select import Select import time time.sleep(1) s=driver.find_element_by_css_selector("#recharge_way") Select(s).select_by_index(1) driver.find_element_by_css_selector('[name="usr"]').send_keys("r0XXXX")#充值账号 driver.find_element_by_css_selector('[name="amount"]').send_keys(10) driver.find_element_by_css_selector('#reason').send_keys("test") driver.find_element_by_css_selector('.buttonContent>button[name="submit"]').click() from selenium.webdriver.common.alert import Alert import time time.sleep(5) driver.find_element_by_css_selector('[rel="callback"]').click()