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