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官方文档----------------
     
  • 相关阅读:
    开发一个App的成本是多少?
    自定义Drawable
    数据库服务软件类型和配置redis
    分库分表
    创建视图
    部署MYSQL高可用集群
    读写分离《二》
    读写分离和多实例
    部署mysql主从同步
    备份和恢复
  • 原文地址:https://www.cnblogs.com/itstu/p/6913061.html
Copyright © 2011-2022 走看看