selenium随笔

1、使用selenium中的webdriver模块对浏览器进行操作

  1)b = webdriver.Firefox()   #打开浏览器

  2)b.get('http://www.baidu.com')  #打开一个网页

      判断url,title找到元素方式

  3)b.title,current_url 判断访问是否有效

  4) ele = find_element_by_id/name()  #定位元素

  5)ele.clear()  ele.send_keys()  清空和输入

  6)b.back()  #back

2、webdriver模块对浏览器进行操作:元素的定位

  7)ele = find_element_by_link_text(‘企业直通班’)

  8)ele = find_element_by_partial_link_text(‘直通班’)

  9)ele = find_element_by_css_selector('input[id=\'search\']')

     ele = find_element_by_css_selector(‘img[alt="麦子学院三周年"]’)

  10)xpath定位文件:/  //  .  ..  @id  count

    ele = find_element_by_xpath('//input')

    ele = find_element_by_xpath('//input[0]')

    ele = find_element_by_xpath('//form//input[0]')

    ele = find_element_by_xpath('//form//input/..')

     find_element_by_xpath('//input[@id]')

    find_element_by_xpath('//input[@name="firstname"]')

    find_element_by_xpath('//*[count(input)=2]')

猜你喜欢

转载自www.cnblogs.com/sasa-python/p/10987373.html
今日推荐