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

点此获取更多相关资料

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

原文链接: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()
相关推荐
weixin_3077791318 分钟前
在AWS上使用Flume搜集分布在不同EC2实例上的应用程序日志具体流程和代码
python·flask·云计算·flume·aws
sirius123451231 小时前
自定义数据集 ,使用朴素贝叶斯对其进行分类
python·分类·numpy
shanks662 小时前
【PyQt】学习PyQt进行GUI开发从基础到进阶逐步掌握详细路线图和关键知识点
python·pyqt
weixin_307779133 小时前
流媒体娱乐服务平台在AWS上使用Presto作为大数据的交互式查询引擎的具体流程和代码
大数据·python·音视频·aws
職場上的造物主3 小时前
高清种子资源获取指南 | ✈️@seedlinkbot
python·ios·php·音视频·视频编解码·视频
〖是♂我〗4 小时前
自定义数据集 使用scikit-learn中svm的包实现svm分类
开发语言·python
抱抱宝4 小时前
Pyecharts之特殊图表的独特展示
python·信息可视化·数据分析
deephub5 小时前
Python GIL(全局解释器锁)机制对多线程性能影响的深度分析
python·机器学习·gil
MatpyMaster6 小时前
基于PyQt5打造的实用工具——PDF文件加图片水印,可调大小位置,可批量处理!
python·pdf
go54631584656 小时前
python 从知网的期刊导航页面抓取与农业科技相关的数据
开发语言·python·科技