selenium get the page source code, determine whether there is a specified content, perform different actions

This case is used to solve the selenium UI Automation, to determine whether there is a specified page text, perform different actions follow

Mainly used browser.page_source

For example, save the file to their share Baidu Baidu disk, where the file is saved will not be deleted

 

If you do not do judgment, the script stops

Put the following in the script, we can solve this problem.

browser.page_source get the current page sources
IF U " shared files have been deleted "  in browser.page_source: # If a file is deleted, skip this cycle, the cycle begins again round 
   the Continue 
the else :

The entire script as follows:

DEF Keep ():
     for Line in Open ( ' C: \\ \\ Beckham the Users Python \\ \\ \\ 1.txt Desktop ' ): # loop reads the address and the extracted code Baidu 
        address = line [0:47] # isolated Baidu disk address 
        code = Line [47:51] # segmented extraction code 
        browser.get (address) # open the link   
        IF U " shared files have been deleted "  in browser.page_source: # If a file is deleted, skip this cycle, the cycle begins again round 
            the Continue 
        the else : 
            browser.find_element_by_id ( " ksrmwk1v " ) .send_keys (code) #Input to the extraction code 
            the time.sleep (2 ) 
            browser.find_element_by_xpath ( " // span [the contains (text (), 'extract file')] " ) .click () 
            the time.sleep ( 2 ) 
            browser.find_element_by_xpath ( " // span [contains (text (), 'save to disk network')] " ) .click () 
            the time.sleep ( 2 ) 
            browser.find_element_by_xpath ( " // span [contains (text (), 'taotu8')] " ). the Click () 
            the time.sleep ( 2 ) 
            browser.find_element_by_xpath ( " // span [the contains (text (), 'OK')]").click()
            time.sleep(5)
keep()

Finish

 

Guess you like

Origin www.cnblogs.com/becks/p/11441430.html