Python+selenium UI Scripting Use Cases

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.