栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

通过selenium进入iframe框架、alert弹窗点击操作

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过selenium进入iframe框架、alert弹窗点击操作

以菜鸟实验

driver.switch_to.frame("iframeResult") #进入frame 通过frame的id值
driver.find_element(By.XPATH,'/html/body/input').get_attribute('value') #获取按钮的文本value,通过get_attribute('value')方法
alert=WebDriverWait(driver,10).until(expected_conditions.alert_is_present()) #等待、定位alert弹窗
driver.switch_to.alert#定位到alert弹窗
alert.accept()#弹窗点击确认accept,点击取消是 dismiss
driver.switch_to.default_content()#回到默认页面,每次进入frame都要重新退出,进入默认页面
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

driver=webdriver.Chrome(executable_path="../../../chromedriver.exe")
driver.get("https://www.runoob.com/try/try.php?filename=tryjs_alert")
driver.switch_to.frame("iframeResult") 
text=driver.find_element(By.XPATH,'/html/body/input').get_attribute('value')
print(text)
driver.find_element(By.XPATH,'/html/body/input').click()
try:
    alert=WebDriverWait(driver,10).until(expected_conditions.alert_is_present())
    time.sleep(5)
    print(alert.text)
    alert=driver.switch_to.alert
    alert.accept()
except Exception as e:
    print(e.args)
driver.switch_to.default_content()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1025953.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号