窗口切换
def test_browser_windows(driver):
# 获取所有窗口的句柄,返回一个list
handles = driver.window_handles
# for循环遍历存放句柄的list,取出每一个窗口的句柄
for h in handles:
# 根据窗口句柄切换窗口
driver.switch_to.window(h)
sleep(2)
# 判断窗口标题中是否包含某个关键字
if "京东" in driver.title:
# 如果包含,中断循环
break
def test_prompt(driver):
driver.find_element_by_xpath('//input[@value="对话框"]').click()
sleep(2)
# 切换到当前浏览器的弹框
alert = driver.switch_to.alert
# 获取弹框文本
print(alert.text)
# 确认
alert.accept()
# 取消
alert.dismiss()
# 写入
alert.send_keys("dfgdfgdfg")
def test_frame(driver):
# 定位iframe
frame = driver.find_element_by_xpath('(//iframe[contains(@id,"vue-tinymce-")])[1]')
# 切入iframe
driver.switch_to.frame(frame)
body = driver.find_element_by_id("tinymce")
body.send_keys("asdfsdfsdfasf")
# 退出当前iframe
driver.switch_to.parent_frame()
# 回到最外层界面
# driver.switch_to.default_content()
driver.find_element_by_xpath('//i[@class="el-icon-plus"]').click()