2025年3月26日 星期三 甲辰(龙)年 月廿五 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > Python

python+selenium之弹窗处理

时间:05-30来源:作者:点击数:44

这个是python+selenium之弹窗处理

  • #coding=utf-8
  • from selenium import webdriver
  • from selenium.webdriver.common.action_chains import ActionChains
  • import time
  • driver = webdriver.Firefox()
  • driver.get('http://www.baidu.com')
  • ele = driver.find_element_by_link_text(u"设置")
  • ActionChains(driver).move_to_element(ele).perform()
  • time.sleep(2)
  • ele1 = driver.find_element_by_link_text(u"搜索设置")
  • ele1.click()
  • ele2 = driver.find_element_by_class_name('prefpanelgo')
  • time.sleep(2)
  • ele2.click()
  • time.sleep(2)
  • #接受告警框
  • driver.switch_to_alert().accept()
  • time.sleep(4)
  • #等等4秒
  • driver.quit()
  • #关闭浏览器
  • '''
  • driver.switch_to_alert().text() 返回告警框的文字
  • driver.switch_to_alert().accept()接受告警框
  • driver.switch_to_alert().dismiss()解散现在告警框
  • driver.switch_to_alert().send_keys(keysToSend) 发送文本至告警框
  • '''
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门