zoukankan      html  css  js  c++  java
  • Python+Selenium学习笔记9

    如下图所示,这种窗口是不能通过前端工具对其进行定位的,这里可以通过switch_to_alert()方法去接受这个弹窗

     1 # coding = utf-8
     2 
     3 from selenium import webdriver
     4 from selenium.webdriver.common.action_chains import ActionChains
     5 import time
     6 
     7 dr = webdriver.Firefox()
     8 dr.get("http://www.baidu.com")
     9 
    10 # 鼠标悬停至“设置”链接
    11 # link = dr.find_element_by_link_text("设置")  #这方法定位不了,又只能靠xpath
    12 link = dr.find_element_by_xpath("/html/body/div[1]/div[1]/div/div[3]/a[8]")
    13 ActionChains(dr).move_to_element(link).perform()
    14 time.sleep(5)
    15 
    16 # 打开搜索设置
    17 dr.find_element_by_link_text("搜索设置").click()
    18 time.sleep(5)
    19 
    20 # 保存设置
    21 dr.find_element_by_class_name("prefpanelgo").click()  # 这是保存按钮的class
    22 time.sleep(5)
    23 
    24 # 接受警告框
    25 dr.switch_to_alert().accept()
    26 
    27 dr.quit()
    switch_to_alert().accept()  接受窗现有警告框
    switch_to_alert().text() 返回窗口的文字信息
    switch_to_alert().dissmiss() 解散现有警告框
    switch_to_alert().send_keys(keysToSend) 发送文本至警告框。keysToSend:将文本发送至警告框 # 没明白keysToSend是什么
     
  • 相关阅读:
    使用 Python 自动键鼠操作实现批量截图 并用工具转成 pdf 文档
    Nginx 常用屏蔽规则
    php 分页中间省略
    php word转pdf 读取pdf内容
    微信公众号发送客服消息
    php ip 城市(百度地图)
    php CURL
    微信网页分享-1.6.0版本
    mamp 安装php扩展
    php查询所有文件
  • 原文地址:https://www.cnblogs.com/sue2015/p/9053971.html
Copyright © 2011-2022 走看看