Webdriver locates frame in frameset
Recently, I was writing an automation script for the page. When I located the frame in frameset, I couldn't locate it. After trying again and again, I finally solved it. I am very gratified. O (∩ _ ∩) O ~
The page structure is as follows:
The problems are as follows: after I successfully logged in, in order to determine the user name, first from the default state driver.switch_to_frame ("topFrame"), but then locate the left menu bar, the element can not be located, by looking at the structure, it turned out to be in another frame (leftFrame), but at this time through driver.switch_to_frame ("leftFrame"), the prompt can not find frame, from the Internet to find the solution Some people say that it is best not to use the driver.switch_to_frame () method, but to use the driver.swich_to (). Frame () method instead, but try it and report the has no _ _ called () _ method, and finally find a way to say: you need to driver.switch_to_defaultContent () first, and then driver.switch_to_fram () to the needed frame, even after you try it.
Solution: first driver.find_element_by_id ("frame") to the frameset of the same level under topFrame, then left_frame = frameset.find_element_by_name ("leftFrame"), and finally driver.switch_to_frame (left_frame).
Summary: the specific method to use, mainly depends on the page structure, different structures use different methods, Wakaka (∩ _ ∩) O ~