软件测试/测试开发丨文件上传与弹窗处理 学习笔记

点此获取更多相关资料

本文为霍格沃兹测试开发学社学员学习笔记分享

原文链接:https://ceshiren.com/t/topic/27071

一、文件上传

  • input标签可以直接使用send_keys("文件路径/文件名")上传文件

    • ele01 = driver.find_element(By.ID,"上传按钮id")
    • ele01.send_keys("文件路径/文件名")
python 复制代码
    def test_upload_file(self):
        self.driver.get("https://image.baidu.com/")
        self.driver.find_element(By.XPATH, '//*[@class="st_camera_off"]').click()
        ele01 = self.driver.find_element(By.ID, 'stfile')
        ele01.send_keys(r"C:\Users\Chen\PycharmProjects\hogwartsCourse\UIAutoTest\UI_L2\pictures\pic01.png")
        time.sleep(5)
        print(self.driver.title)

二、弹窗处理

2.1、弹窗处理机制

  • 在页面操作时,有时会遇到JS生成的alert、confirm、prompt弹窗,我们可以使用switch_to.alert()方法定位到。

  • 操作alert常用的方法:

    • switch_to.alert():获取当前页面的弹窗
    • text:返回弹窗中的文本信息
    • accept():接受现有的弹窗
    • dismiss():解算取消现有的弹窗
    • send_keys():发送文本至弹窗
python 复制代码
    def test_accept_alert(self):
        self.driver.get("https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable")
        self.driver.switch_to.frame("iframeResult")
        ele01 = self.driver.find_element(By.ID, "draggable")
        print(ele01.text)
        ele02 = self.driver.find_element(By.ID, "droppable")
        print(ele02.text)
        self.action.drag_and_drop(ele01, ele02).perform()
        time.sleep(3)
        self.driver.switch_to.alert.accept()
        self.driver.switch_to.parent_frame()
        self.driver.find_element(By.ID,"submitBTN").click()
相关推荐
ATMQuant1 小时前
量化指标解码21:逻辑回归支撑阻力 - 让逻辑回归给关键价位打分
python·机器学习·逻辑回归·量化交易·技术指标
q0371802 小时前
深色 IDE 截图 OCR 老是漏字,我加了一层预处理,顺手把识别结果做成了可搜索历史
python
蜗牛8752 小时前
个人机票监控开源项目:6 个平台、10 条通道的自托管方案
python
秋名山小白3 小时前
Playwright UI 自动化测试实战教程
python·ui
AI源码4 小时前
基于 Python 的汽车市场数据分析与可视化平台
python·数据分析·汽车
会飞锦鲤4 小时前
基于 SVM + HOG 的铸造缺陷检测系统
python·opencv·机器学习·计算机视觉·缺陷检测·图像分类·svm
starrysky8105 小时前
zipfile 中文乱码修复:把已知 GBK 旧 ZIP 解压到正确中文目录
python
用户91294046848425 小时前
Codex 从零到能交付(09):让 Codex 写有用的测试,而不是只测成功路径
python
2601_967987375 小时前
Debian如何配置Python调试工具
python·debian·pdb·调试工具·ipdb
MoRay5 小时前
放弃云端 Computer Use,我用 Python 手搓了一个带“物理防呆”的本地 GUI Agent 底座
python·github