zoukankan      html  css  js  c++  java
  • <自动化测试>之<selenium API 查找元素操作底层方法>

    搜罗了一些查找元素的除标准语句外,另外的语句使用方法,摘自 开源中国 郝云鹏
    driver = webdriver.Chrome(); 打开测试页面 driver.get( "http://baidu.com" ); ---------------页面元素定位(页面元素)-------------- 通过ID进行定位 <div id="coolestWidgetEvah">...</div> #页面代码 ---> element = driver.find_element_by_id("coolestWidgetEvah") 或 from selenium.webdriver.common.by import By element = driver.find_element(by=By.ID, value="coolestWidgetEvah")#个人认为第二种比较麻烦! 通过Class Name定位 <div class="cheese"><span>Cheddar</span></div><div class="cheese"><span>Gouda</span></div>#页面代码 ---> cheeses = driver.find_elements_by_class_name("cheese") 或者 from selenium.webdriver.common.by import By cheeses = driver.find_elements(By.CLASS_NAME, "cheese") 通过Tag Name定位 <iframe src="..."></iframe>#页面代码 ---> frame = driver.find_element_by_tag_name("iframe") 或者 from selenium.webdriver.common.by import By frame = driver.find_element(By.TAG_NAME, "iframe") 通过Name定位 <input name="cheese" type="text"/>#页面代码 ---> cheese = driver.find_element_by_name("cheese") 或者 from selenium.webdriver.common.by import By cheese = driver.find_element(By.NAME, "cheese") 通过Partial Link Text(局部链接文本)定位 <a href="http://www.google.com/search?q=cheese">search for cheese</a>>#页面代码 ---> cheese = driver.find_element_by_partial_link_text("cheese") 或者 from selenium.webdriver.common.by import By cheese = driver.find_element(By.PARTIAL_LINK_TEXT, "cheese") 通过CSS定位 <div id="food"><span class="dairy">milk</span><span class="dairy aged">cheese</span></div>#页面代码 ---> cheese = driver.find_element_by_css_selector("#food span.dairy.aged")或者from selenium.webdriver.common.by import By cheese = driver.find_element(By.CSS_SELECTOR, "#food span.dairy.aged") #不建议使用此方法 因为在官网上提示 不通的浏览器中可能会导致显示不同的css样式 以上为基本的定位 还有一种xpath定位 下次再说. -------------原文为selenium官方文档----------------
     
  • 相关阅读:
    【Windows核心编程】重载类成员函数new / new[] / delete / delete[]
    【数据结构和算法】 O(1)时间取得栈中的最大 / 最小元素值
    路由器与交换机做链路聚合
    怎么样判断两个IP地址是否在同一个网段
    sqlite常用的命令-增删改查
    5G时代的智慧灯杆需要哪种网关?
    什么是边缘计算网关?
    5G/4G工业智能网关在工业物联网的必要性
    基于5G/4G网关的冷冻设备远程监测及故障预警系统
    工业5G网关配置POE技术的优势
  • 原文地址:https://www.cnblogs.com/itstu/p/6913061.html
Copyright © 2011-2022 走看看