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

点此获取更多相关资料

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

原文链接: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()
相关推荐
m0_588758482 分钟前
如何高效批量删除SQL数据_使用脚本分段删除降低压力
jvm·数据库·python
knight_9___5 分钟前
LLM工具调用面试篇2
人工智能·python·深度学习·机器学习·agent·rag
abc123456sdggfd9 分钟前
Layui表单验证失败时如何修改默认弹出的Tips气泡颜色
jvm·数据库·python
MasonYyp11 分钟前
基于Python可定制开发的智能体框架
开发语言·python
weixin_4249993640 分钟前
PHP源码在双硬盘系统如何优化_硬件存储分配建议【指南】
jvm·数据库·python
qq_189807031 小时前
json ignore反序列化?_?JSON反序列化时忽略字段的json----标签使用方法.txt
jvm·数据库·python
zhangchaoxies1 小时前
让水平滚动条始终固定在页面底部,实现跨视口的横向滚动控制
jvm·数据库·python
justjinji1 小时前
如何用组合继承模式实现父类方法复用与子类属性独立
jvm·数据库·python
djjdjdjdjjdj1 小时前
PHP函数如何监控CPU温度传感器_PHP读取核心温度硬件值【详解】
jvm·数据库·python
m0_613856291 小时前
c++怎么把多个变量一次性写入二进制文件_结构体对齐与write【实战】
jvm·数据库·python