zoukankan      html  css  js  c++  java
  • 网页跳转练习

    #coding=utf-8
    import sys
    import time
    import selenium
    from selenium import webdriver
    #from selenium.webdriver.support.wait import WebDriverWait——添加智能等待时间
    def startFirefox(URL):
        driver = webdriver.Firefox()
        driver.get(URL)
        driver.maximize_window()
        time.sleep(3)
    #    wait=WebDriverWait(driver,30)——智能等待30秒
    #    wait.until(lambda driver:river.find_element_by_id('dropdownl').is_displayed()
    ######################################################################################1.打开一个窗口,百度
    #跳转到百度页面
        driver.switch_to.frame('f1')
        driver.switch_to.frame('f2')
    #定位到百度输入框
        driver.find_element_by_id('kw').send_keys('taobao')
    #定位到百度搜索按钮
        driver.find_element_by_id('su').click()
    ######################################################################################2.弹跳框百度
    #跳出百度页面   
        driver.switch_to.default_content()
    #点击弹跳框
        driver.find_element_by_xpath("//input[@value='弹跳框']").click()
        nowhandle=driver.current_window_handle
        time.sleep(2)
    #获得所有窗口
        allhandles=driver.window_handles
        for handle in allhandles:
            if handle!=nowhandle: #比较当前窗口是不是原先的窗口
                driver.switch_to_window(handle) #获得当前窗口的句柄
                time.sleep(2)
        driver.maximize_window()
        driver.switch_to.frame('f2')
        driver.find_element_by_id('kw').send_keys(u"完美世界")
        driver.find_element_by_id('su').click()
        time.sleep(3)
        driver.close()
        driver.switch_to_window(nowhandle)
    ##################################################################3.输入框输入信息
    # email  昵称 手机  ——输入框
        time.sleep(2)
    #清除输入框信息
        driver.find_element_by_id('login-email-address').clear()
        driver.find_element_by_id('login-email-address').send_keys("kejimimi@163.com")
    #######################################################################################4.下拉列表
    # 下拉列表 
        m=driver.find_element_by_id('ShippingMethod')
        m.find_element_by_xpath("//select[@id='ShippingMethod']/option[@value='10.69']").click()
    #############################################################################################5.对话框
    #对话框
        time.sleep(2)
        driver.find_element_by_xpath("html/body/div[1]/div/input[2]").click()
        time.sleep(1)
        alert=driver.switch_to_alert()
        time.sleep(1)
        alert.accept()
    ##########################################################################################6.确认框
    #确认框
        time.sleep(2)
        driver.find_element_by_xpath("html/body/div[1]/div/input[3]").click()
        time.sleep(1)
        alert=driver.switch_to_alert()
        time.sleep(1)
        alert.dismiss()
    ######################################################################################7.提示框
    #提示框
        time.sleep(2)
        driver.find_element_by_xpath("html/body/div[1]/div/input[4]").click()
        time.sleep(1)
        alert=driver.switch_to_alert()
        time.sleep(1)
        alert.send_keys('zhaiyanping')
         time.sleep(2)
        alter = driver.switch_to_alert()
        alter.accept()
        driver.back()
    ##############################################################################
    startFirefox('file:///C:/1111111/iframe.html')  
     
     
     

  • 相关阅读:
    c copy
    IfcVertexLoop
    qt windeployqt 日志
    IfcPolyLoop
    IfcEdgeLoop
    IfcLoop
    QTableWidget
    QList删除元素
    matlab X的负次方函数绘制2
    matlab X的负次方函数绘制1
  • 原文地址:https://www.cnblogs.com/ni-huang-feng-wu/p/14772758.html
Copyright © 2011-2022 走看看