• web自动化之iframe操作


    from selenium import webdriver
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    import time
    
    driver = webdriver.Chrome()
    driver.get("https://ke.qq.com/")
    driver.maximize_window()
    driver.find_element_by_xpath('//a[text()="登录"]').click()
    # 选择账号类型
    name = (By.XPATH,'//a[text()="QQ登录"]')
    WebDriverWait(driver,20).until(EC.presence_of_element_located(name))
    driver.find_element_by_xpath('//a[text()="QQ登录"]').click()
    # 切换iframe需要传的参数,元祖类型,也可以是一个webelement 对象,也可以是iframe的name 或者di属性
    ment = (By.XPATH,'//iframe[@name="login_frame_qq"]')
    # 等待iframe出现,并切入进去
    WebDriverWait(driver,20).until(EC.frame_to_be_available_and_switch_to_it(ment))
    time.sleep(2)
    # 定位元素
    driver.find_element_by_xpath('//span[@class="img_out_focus"]').click()
    # 退出iframe
    driver.switch_to_default_content()
  • 相关阅读:
    Lucky Substrings
    KMP
    圆桌问题(hdu4841)
    codeforces 624C Graph and String
    Joseph(hdu1443)
    The Longest Straight(FZUoj2216)
    C1. 组队活动 Small(BNUOJ)
    A1. 道路修建 Small(BNUOJ)
    Problem 2221 RunningMan(fuzoj)
    CODEFORCEs 621E. Wet Shark and Blocks
  • 原文地址:https://www.cnblogs.com/666666pingzi/p/10568875.html
Copyright © 2020-2023  润新知