zoukankan      html  css  js  c++  java
  • selenium弹出框的处理

    1.页面弹出框的处理

    def webdriverwait_baidu_alert(self):
            '''
             页面弹出框获取:
               1.获取登录元素定位
               2.显性等待
               3.直到登录弹出框出现
            '''
            self.driver.find_element_by_xpath('//div[@id="u1"]//a[@name="tj_login"]').click()
            #进行显性等待,使得操作的元素可见
            ele_locator = "TANGRAM__PSP_10__footerULoginBtn"
            param = (By.ID,ele_locator)
            WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(param))
            #再去操作元素
            self.driver.find_element_by_id(ele_locator).click()
            #此时页面又发生变化,还需要等待,使得操作的元素可见
            ele_locator1 = "TANGRAM__PSP_10__userName"
            param1 = (By.ID,ele_locator1)
            WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(param1))
            #再去获取元素并进行输入
            self.driver.find_element_by_id(ele_locator1).send_keys("1234567")
            self.driver.find_element_by_id("TANGRAM__PSP_10__password").send_keys("111111")
            time.sleep(10)

    2.alert弹出框的处理

    def webdriverwait_windows_alert(self):
            '''
             windows弹出框:
                1.获取页面元素,用显性等待等到alert弹框出现
                2.切换到windows弹出框alert
                3.操作alert弹框选择yes或者no
            '''
            self.driver.find_element_by_xpath('//input[@value="提交"]').click()
            WebDriverWait(self.driver,10).until(EC.alert_is_present())
            #从html页面切换到alert页面
            alert_1 = self.driver.switch_to.alert
            #获取alert的文本内容
            print(alert_1.text)
            time.sleep(4)
            #接收选择ok
            alert_1.accept()
  • 相关阅读:
    MSSQL中with(nolock)的用法
    google reader 使用快捷键
    HTML中em标签的用法
    js正则表达式
    C#中lock关键字的用法
    面试反思
    关于IE6.7.8.FF兼容的问题
    C#中DateTime.Now.Ticks的用法和说明
    JS中eval的用法
    这两天面试时不会的笔试题
  • 原文地址:https://www.cnblogs.com/xiaoxiaolvdou/p/9276592.html
Copyright © 2011-2022 走看看