python + selenium element positioning method

Eight kinds of positioning methods

1, id positioning find_element_by_id ()
2, name positioning find_element_by_name ()
. 3, the positioning class name find_element_by_class_name ()
. 4, Tag name positioning find_element_by_tag_name () / elements are generally not found, as understanding
5, link text positioning find_element_by_link_text () / Ultra link
6, partial link text positioning find_element_by_partial_link_text () / hyperlink portion
7, the positioning method xpath find_element_by_xpath () / more easy to find, on the following two
8, css selector positioning find_element_by_css_selector ()

Frame does not find the above is the need to switch Frame

 

1.frame labels frameset, frame, iframe three kinds, frameset is no different with other common label, it will not affect the normal position, while the frame and iframe will affect the positioning of selenium;
selenium provides switch_to.frame () method to cut into the frame ;
switch_to.frame (Reference)
Reference is passed parameter, used to locate the frame, the object can pass WebElement id, name, index and selenium; and
cases:
driver.switch_to.frame ( "mainFrame event list")
2. Browse window switch is operated by a handle (handle), each window has a handle representing the current window, which pages need to operate a window, the window to switch to the corresponding handle. Switched by driver.switch_to.window (handle) handle
Example:
self.driver.switch_to.window (self.driver.window_handles [. 1])

 

Guess you like

Origin www.cnblogs.com/seven7777/p/11890659.html