selenium记录Spiderbuf例题C01

防止自己遗忘,故作此为记录。

步骤:

(1)进入例题,找到需要点击的元素。

可得button xpath

复制代码
click_xpath: str = r'//li/a[@title="mnist"]'
WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, click_xpath)))
res = driver.find_element(By.XPATH, click_xpath)

注意,此时点击res的attribute是完整url。(卡顿在此步,以为url还需要拼接)

之后发现:

可得final_xpath:

复制代码
final_xpath: str = r"//tbody/tr/td[2]"
WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, final_xpath)))
res: list = driver.find_elements(By.XPATH, final_xpath)

最后计算:

复制代码
res: list[float] = [eval(e.text) for e in res]
s: Decimal = Decimal("0.0")

for each in res:
    s += Decimal(each)
s /= len(res)

print(f"{s=}")

s2=Decimal('3.766666666666666666666666667')
#四舍五入为3.77

完整代码:

python 复制代码
# -*- coding: utf-8 -*-
# -*- file: C01.py  -*-

from decimal import Decimal
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeService

first_url: str = r"https://www.spiderbuf.cn/playground/c01"

service = ChromeService(r"C01\chromedriver-win64\chromedriver.exe")
options = ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_argument("--disable-blink-features=AutomationControlled")

driver = Chrome(options=options, service=service)

driver.get(first_url)

click_xpath: str = r'//li/a[@title="mnist"]'
WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, click_xpath)))
res = driver.find_element(By.XPATH, click_xpath)
driver.implicitly_wait(3)

driver.get(res.get_attribute("href"))

#WebDriverWait(driver, 10).until(lambda driver: driver.current_url != first_url)
final_xpath: str = r"//tbody/tr/td[2]"

WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, final_xpath)))
res: list = driver.find_elements(By.XPATH, final_xpath)

res = [eval(e.text) for e in res]
length: int = len(res)

s1: float = sum(res) / length

s2: Decimal = Decimal("0.0")

for each in res:
    s2 += Decimal(each)

s2 /= length

print(f"{s1=}", f"{s2=}")

driver.close()
相关推荐
Wpa.wk9 小时前
接口测试 - 接口测试工具 Postman-基础使用
经验分享·测试工具·lua·postman
可可南木9 小时前
ICT测试日志 --4--日志记录的格式 中
功能测试·测试工具·pcb工艺
卓码软件测评10 小时前
第三方软件测评机构:【Gatling构建JSON请求体StringBody、ElFileBody和Pebble模板的使用】
测试工具·性能优化·json·测试用例
美团程序员10 小时前
软件测试面试题总结【含答案】
功能测试·测试工具·职场和发展
syt_biancheng14 小时前
大规模考试系统性能优化与风险评估
python·功能测试·selenium·性能优化·postman
卓码软件测评15 小时前
CMA/CNAS软件测评机构:【Gatling XPath检查:XPath语法在XML响应中的应用】
测试工具·单元测试·测试用例
苏生十一_Nojambot1 天前
Postman下载安装与使用汉化版教程
测试工具·postman
卓码软件测评1 天前
软件测试:如何在Postman中配置和自动化OAuth 2.0与JWT认证?
测试工具·单元测试·自动化·测试用例·postman·可用性测试
一念一花一世界1 天前
接口管理工具选型:PostMan与PostIn全面对比指南
测试工具·postman·接口管理工具
软件测试雪儿1 天前
Postman越来越难用了
软件测试·测试工具·jmeter·postman