Selenium系列(7)- 文件上传及弹框处理
input上传
先定位input标签,后使用send_keys(文件地址)上传文件即可
def test_upload_file(self):
self.driver.get("https://image.baidu.com/")
self.driver.find_element_by_xpath("//*[@id='sttb']/img[1]").click()
time.sleep(2)
self.driver.find_element_by_id("stfile").send_keys("D:/users/王甜甜/图片/Saved Pictures/头像/3.JPG")
time.sleep(4)
弹框处理
弹框类型:
- 警告框

- 确认框

- 对话框

🎃ATTENTION:
- 可在浏览器控制台通过
window.alert("警告框")、window.confirm("确认框")、window.prompt("对话框")查看不同弹框效果
操作alert方式
switch_to.alert():切换至alert窗口text:返回alert、confirm、prompt中的值accept:接收现有警告框(确定按钮)dismiss:解散现有警告框(取消按钮)semd_keys():发送文本至警告框
🎃ATTENTION:
- alert无法在页面上无法直接定位到,需要先切换至alert
- alert是一个属性,不是一个方法

浙公网安备 33010602011771号