当前位置:   article > 正文

Selenium 切换 frame/iframe

Selenium 切换 frame/iframe
'''
环境:
Python 3.8
selenium==3.141.0
urllib3==1.26.19
'''
'''
说明:
driver.switch_to.frame() # 将当前定位的主体切换为frame/iframe表单的内嵌页面中
driver.switch_to.default_content() # 跳回最外层的页面
'''
# 判断元素是否在 frame/ifame 中

# 126 邮箱为例
  1. # -*- coding: UTF-8 -*-
  2. from selenium import webdriver
  3. import time
  4. # 谷歌浏览器位置
  5. CHROME_PATH = r'xxx\\chrome.exe'
  6. # 谷歌浏览器驱动地址
  7. CHROMEDRIVER_PATH = r'xxx\\chromedriver.exe'
  8. options = webdriver.ChromeOptions()
  9. options.add_experimental_option("excludeSwitches", ["enable-automation"])
  10. options.add_experimental_option("useAutomationExtension", False)
  11. options.binary_location = CHROME_PATH
  12. driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, options=options)
  13. driver.get('https://www.126.com/')
  14. # 调到 ifame
  15. iframe = driver.find_element_by_tag_name('iframe')
  16. driver.switch_to.frame(iframe)
  17. element = driver.find_element_by_name('email')
  18. element.send_keys('xiaoxiao')
  19. # 跳回最外层的页面
  20. driver.switch_to.default_content()
  21. element = driver.find_element_by_link_text('注册新账号')
  22. element.click()
  23. time.sleep(10)
  24. driver.quit()
'''
参考:
【web端自动化】如何判断页面元素是否嵌套在iframe里面
https://blog.csdn.net/lanniya152/article/details/124364417

python自动化测试selenium(四)切换页面、切换窗口
https://blog.csdn.net/u010835747/article/details/125501993

web自动化:4.2selenium如何实现iframe窗口的切换(3种方法)
https://blog.csdn.net/weixin_48415452/article/details/120035381

python+selenium(11)---操作id为动态变化的frame(iframe)
https://blog.csdn.net/wjgccsdn/article/details/113935626

Selenium之link_text和partial_link_text定位
https://blog.csdn.net/dpl12/article/details/102847074
'''
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/804935
推荐阅读
  

闽ICP备14008679号