python selenium iframe怎么定位_python-selenium -- iframe及滚动条定位方法详解

本文详细介绍了如何使用Python的Selenium库在iframe框架中进行元素定位,包括通过名称、索引或Webelement切换到iframe。同时,文章还讲解了如何处理滚动条之后的元素定位,确保元素在可见区域内,以便进行有效操作。通过示例代码展示了具体的实现方法。
摘要由CSDN通过智能技术生成

一、frame框架里面的元素定位

1.1 iframe定位 -- 先切换到iframe框架-定位-释放iframe

定位到iframe的方法

"""

Switches focus to the specified frame, by index, name, or webelement.

:Args:

- frame_reference: The name of the window to switch to, an integer representing the index,

or a webelement that is an (i)frame to switch to.

:Usage:

driver.switch_to.frame(‘frame_name‘)

driver.switch_to.frame(1)

driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])

"""

#切换到iframe

driver.switch_to.frame("login_frame_qq")

#点击账号密码登录

driver.find_element_by_xpath(‘//a[@id="switcher_plogin"]‘).click()

time.sleep(2)

#输入账号密码

#释放iframe 回到主页面

driver.switch_to.default_content()二、滚动条之后的元素定位2.1 先把元素拖动到可见区域-定位

1、移动

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值