Level positioning
1, positioning a set of objects find_elements ()
举例:
current = os.getcwd()
chrome_driver_path =os.path.join(current,'../webdriver/chromedriver') page_path = os.path.join(current,'../pages/element_samples.html') #本地html文件 driver = webdriver.Chrome(executable_path=chrome_driver_path) driver.get('file://'+page_path) # driver.implicitly_wait(20) elems = driver.find_elements(By.XPATH,'//*/input[@type="radio"]') print(type(elems),len(elems)) i =0 if elems: for el in elems: el.click() print('The first check for% d '% (I + . 1 )) = I + . 1 the time.sleep ( 2 ) the else : Print ( " not found element " ) driver.quit ()
2, targeting two find_element levels:
driver.find_element(By.XPATH,'//div[@id="radio"]').find_element(By.XPATH,'//input[class="AliBaBa"]').click()
3, a multilayer web nest (page has a, two Frame b, wherein b is in the a, b to target content to the need to locate a, and then cut to b)
1) switch_to_frame () method, showing the current location in the frame relating to the handover, which parameter name or id must be
Example:
Frame1 = driver.find_element (By.XPATH, ' // iframes ' ) driver.switch_to.frame (Frame1) driver.find_element (By.XPATH, ' // * / body / INPUT [@ ID = "INPUT1"] ') .send_keys ( ' DSD ' ) driver.find_element (By.XPATH, ' // * / body / INPUT [2] ') .send_keys ( ' DSD ' ) # driver.switch_to_frame ( ' Frame1 ' ) method # unfortunately available, but the new method has the time.sleep ( 3 ) driver.quit ()
2) jump back to the main frame page: driver.switch_to.default_content () # Jump main frame page