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

点此获取更多相关资料

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

原文链接: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()
相关推荐
江厌017 分钟前
移动工作站还是塔式?用三个数判断工位形态,再谈配置
python·移动工作站·塔式工作站·工作站选型·isv认证
川石课堂软件测试12 分钟前
涨薪技术|0到1学会性能测试第8课-Analysis分析图
服务器·数据库·python·sql·jmeter·mysql·容器
学编程的小程16 分钟前
服务器日志太分散不好查?我用Promtail+Loki+Grafana把采集、查询和分析串起来了
服务器·python·grafana
云水初28 分钟前
【项目篇】基于LanGraph的自动处理客服邮件的 Agent汇总
开发语言·笔记·python·学习·fastapi·langgraph
香吧香1 小时前
venv 详解
python
笨笨饿1 小时前
#142_VS Code.map文件插件的用法
git·python·stm32·单片机·嵌入式硬件·物联网·vim
zwd20051 小时前
Manim 竖屏 1080×1920 配置详解:pixel_width、frame_width 怎么写(0.21.0 / 0.22.0 实测)
python·manim·数学动画·短视频制作·manim教程·竖屏视频
Nontee1 小时前
Quartz 新手入门:定时任务的两个承诺
开发语言·windows·python
wewowilling1 小时前
LangChain入门
python·ai·langchain·prompt