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

点此获取更多相关资料

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

原文链接: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()
相关推荐
Kyln.Wu1 分钟前
【python实用小脚本-309】HR×Python改造面试路线规划|从手工排程到智能调度的化学反应,轻松实现路径优化
开发语言·python·面试
于是我说27 分钟前
Python Requests Session Cookies 与 JSON 文件的存取
python·json·dubbo
nix.gnehc33 分钟前
PyTorch自动求导
人工智能·pytorch·python
多恩Stone34 分钟前
【Pytorch 深入理解(2)】减少训练显存-Gradient Checkpointing
人工智能·pytorch·python
mortimer35 分钟前
视频自动翻译里的“时空折叠”:简单实用的音画同步实践
python·ffmpeg·aigc
serve the people39 分钟前
tensorflow tf.function 的 多态性(Polymorphism)
人工智能·python·tensorflow
muxin-始终如一1 小时前
Semaphore 使用及原理详解
java·开发语言·python
水水不水啊1 小时前
通过一个域名,借助IPV6免费远程访问自己家里的设备
前端·python·算法
nju_spy1 小时前
力扣每日一题(11.10-11.29)0-1 和 k 整除系列
python·算法·leetcode·前缀和·单调栈·最大公约数·0-1背包
名扬9111 小时前
webrtc编译问题-ubuntu
开发语言·python