吐血整理 python 从零开始学UI自动化(含代码)持续更新,建议收藏!

编程入门 行业动态 更新时间:2024-10-10 04:23:06

吐血整理 python <a href=https://www.elefans.com/category/jswz/34/1769682.html style=从零开始学UI自动化(含代码)持续更新,建议收藏!"/>

吐血整理 python 从零开始学UI自动化(含代码)持续更新,建议收藏!

第二章

--------------WebDrriver元素定位------------------

白开水笔记,内涵代码可跟着敲一敲,ui自动化必须会的定位

2.0  WebDriver概述

              只支持jdk1.8及以上

              通过ms官方的webdriver支持Edge浏览器

              通过mozilla官方的geckodriver来支持火狐

2.1  安装selenium

              安装命令:   pip install selenium

              查看版本:pip show selenium

       dos 退出某个环境:quit()

       查看安装路径:where python

      

       重要!!安装火狐浏览器驱动

       .31.0

       解压后放到py安装目录下

2.2  WebDriver提供了八中定位元素方式,并提供对应的方法

这个是老方法不用了,仅供了解

                     1*   id                 find_element_by_id("id属性值")

                     2*    name            find_element_by_name("name属性值")

                     3    link text                find_element_by_link_text(“连接文本”)

                     4    partial link text     find_element_by_partial_link_text(“部分连接文本”)

                     5    class name    find_element_by_class_name(“类名”)

                     6    tag name      find_element_by_tag_name(“标记名称”)

                     7*   xpath            find_element_by_xpath(“xpath表达式”)

                     8    css selector         find_element_by_css_selector(“css表达式”)

                           

新方法统一调用find_element()方法,通过类by来声明定位方法,并传入相应的定位参数

示例:

       find_element(定位类型,定位具体信息)

       需要导入类by

       from selenium.webdribermon.by import By

       1*   id                               find_element(By.ID,"id属性值")

       2*    name                          find_element(By.NAME,"name属性值")

       3    link text                find_element(By.LINK_TEXT,“连接文本”)

       4    partial link text     find_element(By.PARTIAL_LINK_TEXT,“部分连接文本”)

       5    class name                  find_elemente(By.LINK_TEXT,“类名”)

       6    tag name                    find_element(By.TAG_NAME,“标记名称”)

       7*   xpath                          find_element(By.XPATH,“xpath表达式”)

       8    css selector         find_element(By.CSS_SELECTOR,“css表达式”)

2.3  ID定位  核心知识点

              from selenium import webdriver   # 导入webdriver

              from selenium.webdrivermon.by import By    #导入By

              from time import sleep       #导入time

              # 对火狐实例化

              d = webdriver.Firefox()

              # 定位元素

              myname = d.find_element(By.ID,"username")

      

更多推荐

吐血整理 python 从零开始学UI自动化(含代码)持续更新,建议收藏!

本文发布于:2024-02-11 07:07:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1679757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:从零开始   代码   建议   收藏   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!