"Python" automated test framework-common methods summary

Source: Internet
Author: User

1. Scroll scroll bar (sometimes the page element elements get right but not echo the correct data, probably because the page first loads very slowly, so the page may have done a scroll to where to load the effect, At this point, we need to use the scroll bar to automatically scroll this code to let the page scroll bar automatically scroll load to simulate manual scrolling scroll bar operation.

1 #Scroll scroll bar '2 defMovescorllbar (driver,down,range1,range2):3Monecount=Random.randint (Range1, Range2)4      forNuminchRange (1, Monecount):5         if(down==" Down"):6Driver.find_element_by_xpath ("//body"). Send_keys (Keys.down)7Sleep (Random.uniform (0.1,0.5))8         Else:9Driver.find_element_by_xpath ("//body"). Send_keys (keys.up)TenSleep (Random.uniform (0.1,0.5)) One     return

2. read File csv

# Read CSV file def Readcsvfile (FilePath):     " R " )    = Csv.reader (csvfile)  #  Returns the iteration type return     Reader

3. write file csv

1 #writes the read content to a new CSV document2 defSavecsvfile (filePath):3CsvFile2 = open (FilePath,'W', newline="')#set newline, otherwise there will be a blank line between the two lines4writer =Csv.writer (csvFile2)5Writer.writerow (['UserName','PWD','Result'])6 writer.writerows (outputstring)7     #csvfile.close ()

"Python" automated test framework-common methods summary

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.