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

    1.selenium简述

    2.selenium结合浏览器实战。

    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get("http://www.baidu.com")
    driver.find_element_by_id("kw").send_keys("Selenium")
    driver.find_element_by_id("su")
    driver.close()

    3.元素定位实战

    在UI自动化测试中,最核心的技能是对元素进行定位,定位到相应的元素以后才可以对页面的操作进行编码验证。

    3.1调试工具

    3.2单个元素定位

      在selenium自动化测试中,提供了单个元素定位方式和多个元素定位两种方式。两种方式都是根据元素的属性ID,NAME,CLASS_NAME,TAG_NAME,CSS_SELECTOR,XPATH,LINK_TEXT,PARTAL_LINK_TEXT来进行定位。

    1. find_element_by_id

    通过元素属性ID定位到元素,方法是find_element_by_id。这里以百度输入框为例:

    <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">

    他的ID属性是kw,在百度搜索输入框输入搜索的关键字“selenium”的代码如下

    2.find_element_by_name

    通过元素属性name定位元素,方法是find_element_by_name。她的name元素属性石wd,百度搜索输入框输入搜索的关键字“selenium”的代码如下:

    3.class_name

    4.xpath

    5.find_element_by_link_text

    6.find_element_by_partial_link_text

    7.find_element_by_css_selector

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

    3.3 多个元素定位

    1.find_elements_by_tag_name

    2.find_element_by_id

    多个元素的定位思路是一样的

     3.4 By类的分析

     3.5 iframe元素定位实战

    2.处理嵌套的iframe

  • 相关阅读:
    spring3 的restful API RequestMapping介绍
    论文笔记之:DualGAN: Unsupervised Dual Learning for Image-to-Image Translation
    (zhuan) Some Talks about Dual Learning
    论文笔记之 SST: Single-Stream Temporal Action Proposals
    论文笔记之:Action-Decision Networks for Visual Tracking with Deep Reinforcement Learning
    Tutorial: Generate BBox or Rectangle to locate the target obejct
    论文阅读:CNN-RNN: A Unified Framework for Multi-label Image Classification
    关于 Image Caption 中测试时用到的 beam search算法
    论文阅读: End-to-end Learning of Action Detection from Frame Glimpses in Videos
    (转)Awesome Courses
  • 原文地址:https://www.cnblogs.com/Chamberlain/p/11198507.html
Copyright © 2011-2022 走看看