zoukankan      html  css  js  c++  java
  • python+selenium下弹窗alter对象处理02


    首先使用switch_to.alert()方法进行定位,然后可以使用下面的操作

    text:返回alert、confirm、prompt中的文字信息;

    accept():接受现有警告框;

    dismiss():解散现有警告框;

    send_keys():在警告框中输入文本(如果可以输入的话);



    ---------------------------------------------------------------------------------------

    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    from time import sleep


    driver = webdriver.Firefox() # 指定和打开浏览器
    driver.get('http://www.baidu.com')


    link = driver.find_element_by_link_text("设置")
    ActionChains(driver).move_to_element(link).perform() #鼠标悬停在上面
    sleep(5)
    driver.find_element_by_class_name("setpref").click() #点击高级搜索

    sleep(5)
    driver.find_element_by_class_name('prefpanelgo').click() #点击保存


    sleep(5)
    print(driver.switch_to.alert.text) #获取打印警告框里面的内容

    sleep(5)
    driver.switch_to.alert.accept() #点击确定

    sleep(5)
    driver.close()
  • 相关阅读:
    Leetcode#129 Sum Root to Leaf Numbers
    Leetcode#15 3Sum
    Leetcode#16 3Sum Closest
    Leetcode#127 Word Ladder
    Leetcode#2 Add Two Numbers
    Leetcode#18 4Sum
    vue.js入门(3)——组件通信
    vue.js慢速入门(2)
    vue 基础介绍
    vue.js中v-for的使用及索引获取
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12041030.html
Copyright © 2011-2022 走看看