1. Recently in a company's tool to pull some business data found that there are a lot of duplicate page operations, each time to repeat the selection of the organization and the corresponding table, click Add Action (more than 10 organizations add up to manually added 200 times), so in Python wrote a UI script to the machine to perform these repeated operations, That is, time-saving and high efficiency.
#coding: UTF8
From selenium import Webdriver
From config.params Import *
From Selenium.webdriver.support.ui import Select
Import time
Class PullData ():
Path= "E:/chromedriver.exe" def __init__ (self,url): Self.url=url self.wd = Webdriver. Chrome (Self.path) def openbrowser (self): Self.wd.get (Self.url) Self.wd.maximize_window () def closebrowser (self): SE Lf.wd.quit () def findeleorg (self): hospitals = self.wd.find_elements_by_css_selector ("select[name= ' Hospitalcode ') >option ") return hospitalsdef findeledept (self): Hospitaldatatype = Self.wd.find_elements_by_css_selector (' Select [name$= "DataType"]>option ') return hospitaldatatypedef deletecords (self): while True:cords=self.wd.find_e Lements_by_css_selector ("table[border= ' 1 '] tr>td:nth-of-type (8) >input[value= ' delete ']") If Len (cords) ==0: Break Cords[0].click () time.sleep (1) #定位元素前后要加等待时间, especially the refreshed page def hospitalconfig (self): Self.wd.find_ Element_by_partial_link_text (U "Hospital View SQL"). Click () hospitals=self.findeleorg () hospitaldatatype=self.findeledept () For NUM in range (len (hospitals)-1): Hospitals = Self.findEleorg () Hospitals[num].click () for Numdata in range (len (hospitaldatatype)-1): Hospitals = Self.f Indeleorg () Hospitals[num].click () Hospitaldatatype = Self.findeledept () time.sleep (1) Hospitaldatatype[numdata].click () Time.sleep (2) self.wd.find_element_by_css_selector ("Input [type= ' Submit ']. Click () self.wd.find_element_by_id ("submit_id"). Click () SELF.WD.FIND_ELEMENT_BY_PA Rtial_link_text (U "Hospital View SQL"). Click ()
If name= = "main":
Pulld = PullData (URL)
Pulld.openbrowser ()
Pulld.hospitalconfig ()
Pulld.deletecords ()
Python+selenium UI Scripting Use Cases