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()
相关推荐
llilian_166 小时前
信号发生器 多通道多功能脉冲信号发生器应用解决方案 多功能脉冲发生器
功能测试·单片机·嵌入式硬件·测试工具
程序员小远7 小时前
使用Postman进行一次完整的接口测试
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman
我的xiaodoujiao7 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 44--将自动化测试结果自动推送至钉钉工作群聊
前端·python·测试工具·ui·pytest
生活很暖很治愈8 小时前
GUI自动化测试[3]——控件&数鼠标操作
windows·python·功能测试·测试工具
我的xiaodoujiao10 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 45--生成项目需要的requirements.txt依赖文件
python·学习·测试工具·pytest
uyeonashi12 小时前
Boost搜索引擎测试报告
功能测试·selenium·搜索引擎
@zulnger14 小时前
selenium 自动化测试工具实战项目(订单)
selenium·测试工具·自动化
深圳博众测控1 天前
博众测控 | ISO 16750-2:2023汽车电气测试新标准解读:关键变化与测试设备选型
人工智能·测试工具·汽车
测试界的世清1 天前
金九银十软件测试面试题(800道)
测试工具·面试·职场和发展
帝落若烟1 天前
loadrunner {“msg“:“请求访问:/getInfo,认证失败,无法访问系统资源“,“code“:401}
测试工具·压力测试