Selenium_随记要点

 
1.selenium不支持定位复合元素定位:
    像上图的class元素有两个值: op_weather4_twoicon_today  -----    OP_LOG_LINK
   像这种情况我们只需要一个值就可以了:op_weather4_twoicon_today 或者    OP_LOG_LINK  
 
2.但定位一组元素的时候,selenium默认定位到满足条件的元素
 
 
3.css选择器用Jquery定位元素的时候,默认定位页面所有满足条件的元素,一组元素
 
4.定位元素的时候,get到一个点,现在chrome中Console,调好定位到元素,再统一copy在selenium脚本里面,这样就能提高定位元素效率了!
   document.querySelector('.op_weather4_twoicon_day')  
定位一组元素:    document.querySelectorAll('.op_weather4_twoicon_day ').length 
5.__init__方法是在类实例化的时候调用(new一个对象的时候):
   if__name__=='__main__':
 
6.(怎么等待某个东西出现)Selenium如何等待一个页面的元素:需要导Pythondriverwait类,智能等待某个元素出现
 # 找到id为dropdown1的父元素
webdriverwait默认传两个参数,一个是驱动(dr),一个是等待时间(time) 
WebDriverWait(dr,10).until(lamba the_driver:
   the_driver.find_element_by_id('droupdown1').is_displayed())
7. 27 ~ 32℃---如果要去掉'℃ ':  
    # 27 ~ 32℃ ->27 ~ 32 -> ['27', '32'] ->32  --->这样就拿到32了
      tmp_text=27 ~ 32℃ 
      high_temp = tmp_text.replace('℃','').split('~')[-1].strip()
强转成整数: return int(high_temp)
posted @ 2017-07-20 16:03  Admin_sys  阅读(330)  评论(0编辑  收藏  举报