当前位置: 首页 > news >正文

档案信息网站建设工作经验设计制作平板电脑支架

档案信息网站建设工作经验,设计制作平板电脑支架,龙岩天宫山旅游攻略,网络系统管理员在哪里场景 点击添加”新增“按钮#xff0c;弹出”新增对话框“#xff0c;输入各种数据#xff0c;然后点击”确定“按钮#xff0c;如此循环。数量多#xff0c;这样操作累人。 selenium Selenium 是一个用于自动化 Web 浏览器操作的库#xff0c;可以实现模拟点击、输入…场景 点击添加”新增“按钮弹出”新增对话框“输入各种数据然后点击”确定“按钮如此循环。数量多这样操作累人。 selenium Selenium 是一个用于自动化 Web 浏览器操作的库可以实现模拟点击、输入文本等操作。 代码实现 #!/usr/bin/env python3 # -*- coding: utf-8 -*-from selenium import webdriver from selenium.common.exceptions import ElementNotInteractableException from selenium.common.exceptions import ElementNotSelectableException from selenium.common.exceptions import InvalidSelectorException from selenium.common.exceptions import NoSuchAttributeException from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchFrameException from selenium.common.exceptions import NoSuchWindowException from selenium.common.exceptions import TimeoutException from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select import time# 目标页面 target_url https://test.abc.com/12311/application/#/application/update/2310?modeeditenvprod# 创建一个Chrome浏览器实例 #browser webdriver.Chrome(executable_pathdriver_path) browser webdriver.Chrome()# 打开一个网页 browser.get(target_url) time.sleep(0.5)try:# 点击“快速登录”按钮print(模拟点击“快速登录”按钮)browser.find_element(By.ID, btn_quicklogin).click()time.sleep(1)print(模拟点击“下一步”按钮)# 使用 class 属性定位button browser.find_element(By.CSS_SELECTOR, .footerbutton)button.click()time.sleep(1)# 填充for index, metric_pair in enumerate(metric_pair_array):metric metric_pair.split(:)print(\033[93m\033[0m)print((%d) %s % (len(metric), metric_pair))if len(metric) 2:metric_name metric[0]li_element_index index * 10print(metric_name:%s, index:%d, li_element_index:%d % (metric_name, index, li_element_index))# 点击“新增”按钮browser.find_element(By.CSS_SELECTOR, .table-view__operations-left.t-button--theme-primary).click()time.sleep(1)# 中文名browser.find_element(By.CSS_SELECTOR, .t-form-item__metric_chname .t-input__inner).send_keys(metric_name)# 英文名browser.find_element(By.CSS_SELECTOR, .t-form-item__metric_enname .t-input__inner).send_keys(metric_name)# 类型print(点击“箭头”按钮)browser.find_element(By.CSS_SELECTOR, .t-form-item__type .t-input--suffix).click()li_elements browser.find_elements(By.CSS_SELECTOR, .t-select__dropdown .t-select__list .t-size-m) # li_elements 为大小为 4 的 listprint(type of li_elements: %s % type(li_elements))if isinstance(li_elements, list): # 判断元素是否为列表类型print(size of li_elements: %s % len(li_elements))target_li li_elements[0 li_element_index]target_li.click()# 单位print(点击“箭头”按钮)browser.find_element(By.CSS_SELECTOR, .t-form-item__unit .t-input--suffix).click()li_elements browser.find_elements(By.CSS_SELECTOR, .t-select__dropdown .t-select__list .t-size-m) # li_elements 为大小为 10 的 list包含了前面一步得到的 4 个print(type of li_elements: %s % type(li_elements))if isinstance(li_elements, list):print(size of li_elements: %s % len(li_elements))target_li li_elements[6 li_element_index]target_li.click()# 点击“确定”按钮browser.find_element(By.CSS_SELECTOR, .t-dialog__footer .t-button--theme-primary).click()print() except ElementNotInteractableException as msg:print(uElement not interactable: %s % (msg)) except ElementNotSelectableException as msg:print(uElement not selected: %s % (msg)) except InvalidSelectorException as msg:print(uInvalid selector: %s % (msg)) except NoSuchAttributeException as msg:print(uAttribute not found: %s % (msg)) except NoSuchElementException as msg:print(uElement not found: %s % (msg)) except NoSuchFrameException as msg:print(uFrame not found: %s % (msg)) except NoSuchWindowException as msg:print(uWindow not found: %s % (msg)) except TimeoutException as msg:print(uFind element timeout: %s % (msg)) else:input(按 “Enter” 键退出 ...)# 关闭浏览器 #browser.quit()find_element 在 Selenium 中find_element 方法用于定位页面元素通常与 CSS 选择器一起使用。在 CSS 选择器中和空格有着不同的含义 . 这是一个类选择器。它选择所有具有指定类名的元素。例如 .myClass 会选择所有具有类名 myClass 的元素。 这是一个子元素选择器。它选择所有直接的子元素。例如div p 会选择所有 div 元素的直接子元素 p。 空格 这是一个后代选择器。它选择所有的子元素不仅仅是直接的子元素还包括孙子元素、曾孙元素等。例如div p 会选择 div 元素下的所有 p 元素无论p元素是 div 的直接子元素还是更深层次的后代元素。 这两个选择器在定位元素时非常有用可以帮助更精确地选择想要的元素。如果目标存在多个则应当使用 find_elements。 By.CSS_SELECTOR 和 By.CLASS_NAME 在 Selenium 中By.CSS_SELECTOR 和 By.CLASS_NAME 都是用于定位页面元素的方法但它们的使用方式和目标有所不同。 By.CSS_SELECTOR 这个方法允许使用 CSS 选择器来定位页面元素。CSS 选择器是一种强大的定位方式可以通过元素的属性、层次结构和伪类等来定位元素。例如可以使用 By.CSS_SELECTOR 来定位具有特定 ID、类名、属性或子元素的元素。 # 定位具有特定ID的元素 element browser.find_element(By.CSS_SELECTOR, #element_id)# 定位具有特定类名的元素 element browser.find_element(By.CSS_SELECTOR, .element_class)# 定位具有特定属性的元素 element browser.find_element(By.CSS_SELECTOR, input[typetext])# 定位具有特定子元素的元素 element browser.find_element(By.CSS_SELECTOR, div p)By.CLASS_NAME 这个方法专门用于定位具有特定类名的元素。它只能通过类名来定位元素而不能使用其他属性或层次结构。如果只需要根据类名来定位元素By.CLASS_NAME 是一个简单直接的选择。 # 定位具有特定类名的元素 element browser.find_element(By.CLASS_NAME, element_class)总之By.CSS_SELECTOR 提供了更多的灵活性和定位能力而 By.CLASS_NAME 则专注于通过类名来定位元素。根据需求和目标元素的特点可以选择使用适当的方法来定位页面元素。
http://www.w-s-a.com/news/806750/

相关文章:

  • 东莞做网站公司在哪哪里有网站培训的
  • 做宣传 为什么要做网站那重庆网站建设公司在线联系
  • 网站设计制作售价多少钱制作图片的软件是
  • 网站验证码目录简单带数据库的网站模版
  • 制作网站用c#做前台网站建设专题的意义
  • 广西建设职业技术学院教育网站牡丹区建设局网站
  • 网站后台怎么用ftp打开上海外贸进出口有限公司
  • 淘宝建设网站的意义大学生做那个视频网站
  • 如何提高你的网站的粘性建设银行流水网站
  • 微信h5在哪个网站做泰州专业网站制作公司
  • 现在.net做网站的多吗建设工程造价网
  • pc访问手机网站跳转违法网站开发人员
  • 网站前端做报名框wordpress 启动慢
  • 沈阳做网站客户多吗前端可以做网站吗
  • 网站设计规划书新媒体营销策略分析
  • dw个人网站主页怎么做天津工程信息建设网
  • 顺义做网站的公司网站页面设计基础教程
  • 安阳哪个公司做网站好企业没有做网站有的坏处
  • 网站开发有必要用php框架wordpress分页导航代码
  • wordpress建站seo鞍山制作网站哪家好
  • 网站空间流量查询上海门户网站制作
  • 网站开发技术是什么专业会的加强普法网站和普法网络集群建设
  • 上海建筑网站seo 推广
  • 乌兰察布做网站公司爱站网关键词挖掘工具站长工具
  • 白银网站建设白银申请网站空间怎么做
  • 免费炫酷网站模板网站建设需要用到什么软件有哪些
  • 电商网站开发 文献综述大型网站建设企业
  • 如何在建设部网站补录项目单仁牛商
  • 社保网站上做减员一直不审核软件程序开发
  • 网站友情链接购买天元建设集团有限公司资质