selenium python 定位一组对象

为什么定位一组对象?

定位一组对象的思想
   在定位一组对象的过程中我们如何实现?以前的都是通过具体的对象定位,那么定位一组我们就需要通过css来定位   在单个定位对象中使用的是find_element_by_id()  但是定位一组对象需要使用find_elements_by_css_selector
 
eg:
#定位所有的checkbox对象
checkboxs = dr.find_elements_by_css_selector('input[type=checkbox]')
for checkbox in checkboxs :
     checkbox .click()
 
 
如果需要定位一个页面中所有类型等于某个的时候呢?
inputs = dr.find_elements_by_tag_name('input')
for input in inputs:
     if input.get_attribute('type')=='checkbox':
          input.click()
 
当然也可以通过先定位一个父节点,然后再通过父节点在定位一组
 
select = find_element_by_id('uid').find_elements_by_tag_name("option")
for i in select:
  i.click()
原文地址:https://www.cnblogs.com/Mushishi_xu/p/4329710.html