python3.x: Get the source preamble of the IFRAME embedded page
In some Web pages often see Ifrmae/frame tags, iframe is the embedded framework is generally used to embed another page in an existing page, when an element in the IFRAME, we should first switch to the IFRAME inside.
Syntax 1. Entering an IFRAME
iframe = Self.driver.find_element_by_xpath ("//iframe[contains (@src, ' https://************/auth?e_p=1 &response_type=token ')]self.driver.switch_to.frame (iframe)
2. Release/Exit IFRAME
Driver.switch_to_default_content ()
Instance Code
fromSeleniumImportWebdriver#Open BrowserDriver =Webdriver. Chrome ()#Maximize Your browserDriver.maximize_window ()#Open PageDriver.get ("http://****************/center_tjbg.shtml")#extract all elements that match a specific text through the CONTAINS functionframe = Driver.find_element_by_xpath ("//iframe[contains (@src, ' http://*********************/monthview.action?action=china&channelfidstr= E990411f19544e46be84333c25b63de6 ')]")#go to IFRAME pageDriver.switch_to.frame (frame)#get the Select labelselect = driver.find_element_by_id ("Channelfidstr")#get the option tag in select and note the use of find_elementsOptions_list=select.find_elements_by_tag_name ('option')#Traverse Option forOptioninchoptions_list:#gets the value and text of the drop-down box Print("Value is:%s Text is:%s"% (Option.get_attribute ("value"), Option.text))#Click the Query button eventDriver.find_element_by_css_selector ("input[class = ' btn ']"). Click ()#exit IFrameDriver.quit ()
Integrated Man
Links:http://www.cnblogs.com/lizm166/p/8367499.html
Source: Blog Park
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
python3.x: Get the source code of the IFRAME embedded page