zoukankan      html  css  js  c++  java
  • selenium定位一组元素

      前面我们学习过八大定位,八大定位都是对单个元素进行定位,selenium还提供复合定位方法,同样也有八种,注意单个元素是element,一组元素是elements,如下:

    • find_elements_by_name
    • find_elements_by_id
    • find_elements_by_css_selector
    • find_elements_by_class_name
    • find_elements_by_link_text
    • find_elements_by_partial_link_text
    • find_elements_by_xpath
    • find_elements_by_tag_name

    用例:

    1. 打开百度首页
    2. 点击“设置”
    3. 单击“搜索设置”
    4. 实现选中红框内第2个单选按钮

       通过查看页面元素得知,3个选项“全部语言”、“仅简体中文”,“仅繁体中文”,name都为SL

    5. 实现代码:

      from selenium import webdriver
      import time
      from selenium.webdriver.common.action_chains import ActionChains
      #大牛测试:轻轻松松自动化
      #QQ:2574674466
      driver = webdriver.Chrome()
      driver.get('https://www.baidu.com')
      #最大化窗口,防止元素被遮住
      driver.maximize_window()
      #悬停
      ActionChains(driver).move_to_element(driver.find_element_by_css_selector("#s-usersetting-top")).perform()
      #单个元素不要加s
      time.sleep(2)
      driver.find_element_by_class_name("setpref").click()
      time.sleep(2)
      #复合定位
      check =driver.find_elements_by_name("SL")
      print(check)
      print(len(check))
      check.pop(1).click()


       
    自动化测试有问题请加qq:2574674466,关注公众号“大牛测试”,转发朋友全,免费领取视频版教程

     

    欢迎加入交流群:Selenium学习群: 628908894
  • 相关阅读:
    c# 字符串中某个词出现的次数及索引
    c# 冒泡排序
    WCF 高级知识
    Web Api基础知识
    Web Services基础知识
    WCF Demo
    IIS部署WCF常见错误
    IIS部署WCF
    IIS部署WCF错误
    WCF基础知识
  • 原文地址:https://www.cnblogs.com/tim2016/p/15382992.html
Copyright © 2011-2022 走看看