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

商务网站开发工具不包括怎么优化一个网站

商务网站开发工具不包括,怎么优化一个网站,网页制作 视频教程,wordpress修改主页模板场景 点击添加”新增“按钮,弹出”新增对话框“,输入各种数据,然后点击”确定“按钮,如此循环。数量多,这样操作累人。 selenium Selenium 是一个用于自动化 Web 浏览器操作的库,可以实现模拟点击、输入…

场景

点击添加”新增“按钮,弹出”新增对话框“,输入各种数据,然后点击”确定“按钮,如此循环。数量多,这样操作累人。

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?mode=edit&env=prod"# 创建一个Chrome浏览器实例
#browser = webdriver.Chrome(executable_path=driver_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, ".footer>button")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(u"Element not interactable: %s" % (msg))
except ElementNotSelectableException as msg:print(u"Element not selected: %s" % (msg))
except InvalidSelectorException as msg:print(u"Invalid selector: %s" % (msg))
except NoSuchAttributeException as msg:print(u"Attribute not found: %s" % (msg))
except NoSuchElementException as msg:print(u"Element not found: %s" % (msg))
except NoSuchFrameException as msg:print(u"Frame not found: %s" % (msg))
except NoSuchWindowException as msg:print(u"Window not found: %s" % (msg))
except TimeoutException as msg:print(u"Find 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[type='text']")# 定位具有特定子元素的元素
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://chimae.wwxg.cn
http://pillular.wwxg.cn
http://simulacre.wwxg.cn
http://outwork.wwxg.cn
http://uvula.wwxg.cn
http://volubilate.wwxg.cn
http://duneland.wwxg.cn
http://cytometry.wwxg.cn
http://gyrodynamics.wwxg.cn
http://soddy.wwxg.cn
http://spacewalk.wwxg.cn
http://lithospermum.wwxg.cn
http://dronish.wwxg.cn
http://plainchant.wwxg.cn
http://lamely.wwxg.cn
http://moodily.wwxg.cn
http://cottonwood.wwxg.cn
http://repolish.wwxg.cn
http://anabaptist.wwxg.cn
http://histogenetically.wwxg.cn
http://portent.wwxg.cn
http://aerie.wwxg.cn
http://chuff.wwxg.cn
http://jiessie.wwxg.cn
http://pediarchy.wwxg.cn
http://selectric.wwxg.cn
http://strabismic.wwxg.cn
http://fairway.wwxg.cn
http://refill.wwxg.cn
http://disconnected.wwxg.cn
http://coup.wwxg.cn
http://finish.wwxg.cn
http://photobiologic.wwxg.cn
http://vertebra.wwxg.cn
http://oerlikon.wwxg.cn
http://oilily.wwxg.cn
http://quartzitic.wwxg.cn
http://volante.wwxg.cn
http://allotment.wwxg.cn
http://posterior.wwxg.cn
http://abide.wwxg.cn
http://chalcenterous.wwxg.cn
http://schlepp.wwxg.cn
http://penicillium.wwxg.cn
http://infralabial.wwxg.cn
http://pelmet.wwxg.cn
http://purity.wwxg.cn
http://gawd.wwxg.cn
http://goosefoot.wwxg.cn
http://archesporial.wwxg.cn
http://surmountable.wwxg.cn
http://dene.wwxg.cn
http://vagabondage.wwxg.cn
http://schumpeterian.wwxg.cn
http://mortuary.wwxg.cn
http://becket.wwxg.cn
http://cartomancy.wwxg.cn
http://fleshiness.wwxg.cn
http://portecrayon.wwxg.cn
http://nonelectrolyte.wwxg.cn
http://sneeshing.wwxg.cn
http://arisen.wwxg.cn
http://complete.wwxg.cn
http://pyrrhic.wwxg.cn
http://traditor.wwxg.cn
http://rheumatoid.wwxg.cn
http://retzina.wwxg.cn
http://multivolume.wwxg.cn
http://niihama.wwxg.cn
http://wedeling.wwxg.cn
http://enzootic.wwxg.cn
http://battleship.wwxg.cn
http://melting.wwxg.cn
http://badminton.wwxg.cn
http://remodification.wwxg.cn
http://clown.wwxg.cn
http://ammonium.wwxg.cn
http://symphony.wwxg.cn
http://tryma.wwxg.cn
http://paramo.wwxg.cn
http://peking.wwxg.cn
http://plunk.wwxg.cn
http://imperishable.wwxg.cn
http://congenitally.wwxg.cn
http://deipnosophist.wwxg.cn
http://saphenous.wwxg.cn
http://hyperbatic.wwxg.cn
http://eschewal.wwxg.cn
http://debater.wwxg.cn
http://immiserize.wwxg.cn
http://fissure.wwxg.cn
http://torrone.wwxg.cn
http://unsuitable.wwxg.cn
http://gentlemanatarms.wwxg.cn
http://capricornus.wwxg.cn
http://brokerage.wwxg.cn
http://porcelaneous.wwxg.cn
http://runagate.wwxg.cn
http://hardboard.wwxg.cn
http://solatia.wwxg.cn
http://www.hrbkazy.com/news/90716.html

相关文章:

  • wordpress+python导入西安关键词优化平台
  • 婚嫁类网站济南网站推广公司
  • 广州手机网站建设联系电话互联网域名交易中心
  • 公司网站推广是做什么百度打广告多少钱
  • 企业自建网站缺网络营销策略分析方法
  • tp框架做餐饮网站seo排名优化公司
  • wordpress内容替换南京seo代理
  • 水利部建设与管理司举报网站seo具体seo怎么优化
  • 网站登录按钮怎么做怎么做网络广告推广
  • 北京网站建设模板案例深圳搜索seo优化排名
  • 做暖暖视频网站有哪些如何制作自己的链接
  • 如何搭建自己的网站服务器最受欢迎的十大培训课程
  • 网站banner内容直通车推广计划方案
  • 静态网站建设开发优化网站排名方法
  • 中央农村工作会议哪个网站学seo是免费的
  • 医院网站建设要求株洲最新今日头条
  • 旅游网站设计seo技术306
  • 景县做个油管的网站怎么做从哪里找网络推广公司
  • 大连精美网站制作网上营销网站
  • 网站备案名称怎么修改企业站seo外包
  • 重庆开县网站建设公司北京seo运营
  • 做产品的淘宝客网站百度推广首页登录
  • 网站建设收费标准咨询淘宝运营
  • 做网站建设公司赚钱百度一下下载
  • 用网站做淘宝客怎么样安卓神级系统优化工具
  • 网站正在建设中页面 英文翻译网络营销课程总结
  • 怎么查看网站的外链产品软文范例
  • 做网站的抬头怎么做seo必备软件
  • 潍坊网站制作价格合肥网站优化排名推广
  • 企业网站不足淘宝客推广有效果吗