selenium模块,web自动化,获取标签页

1.获取标签页数

lables = test.window_handles
print(lables)

 

2. 切换标签页

lables = test.window_handles
test.switch_to.window(lables[2])

 

3.警告框alert元素交互(页面弹出框)

# 关闭弹窗
test.switch_to.alert.accept()
# 获取弹窗内容
st = test.switch_to.alert.text
print(st)

 

4. 确认框confirm元素交互

# 确定
test.switch_to.alert.accept()
# 取消
test.switch_to.alert.dismiss()

 

5. iframe嵌套页面进入、退出

a = test.find_element(By.XPATH, value='/html/body/iframe')
# 进入iframe嵌套页面
test.switch_to.frame(a)
# 操作iframe页面元素
test.find_element(By.XPATH, value='')

# 退出嵌套页面
test.switch_to.default_content()

 

6. 判断元素内容是否可见(返回false/true)

a = test.find_element(By.XPATH, value='/html/body/iframe').is_displayed()

 

7. 网页前进、后退

# 网页后退
test.back()
# 网页前进
test.forward()

 

posted @ 2024-11-23 23:31  铿锵有力自信且坚定  阅读(80)  评论(0)    收藏  举报