2个iframe的xpath一致,根据内容去定位xpath

//*[@id="layui-layer-iframe2"]

/html/body/div[4]/div[2]/iframe

<iframe scrolling="auto" allowtransparency="true" id="layui-layer-iframe2" name="layui-layer-iframe2" onload="this.className='';" class="" frameborder="0" src="/SC/SCBM/SCBM_new?_Bmddj.com_id=SH01&amp;_Bmddj.mdid=SC&amp;_Bmddj.djid=BM&amp;_Bmddj.fid=200872&amp;_Bmddj.ver_i=v1&amp;_Bmddj.act_type=BOM信息录入&amp;_Bmddj.act_name=Act5&amp;_Bmddj.opr_flag=N&amp;_Bmddj.org_mdid=SC&amp;_Bmddj.org_djid=BM&amp;_Bmddj.act_flag=A&amp;_Bmddj.flw_flag=&amp;_Bmddj.mdid_opr_flag=*" style="height: 1263px;"></iframe>

//*[@id="layui-layer-iframe2"]

/html/body/div[4]/div[2]/iframe

<iframe scrolling="yes" allowtransparency="true" id="layui-layer-iframe2" name="layui-layer-iframe2" onload="this.className='';" class="" frameborder="0" src="/PublicArea/Public/select_item?endFlag=parent.beforeItemSelect(dtsData);&amp;mdid=SC&amp;djid=BM&amp;kvs_str={&quot;select_item_no&quot;:&quot;item_no&quot;,&quot;select_item_name&quot;:&quot;item_name&quot;,&quot;select_item_spec&quot;:&quot;spec&quot;,&quot;select_type_no&quot;:&quot;type_no&quot;,&quot;select_item_pattern&quot;:&quot;pattern&quot;,&quot;select_item_type&quot;:&quot;item_type&quot;,&quot;unit_id&quot;:&quot;item_unit&quot;,&quot;unit_name&quot;:&quot;unit_name&quot;}&amp;_Bmddj.com_id=SH01&amp;_Bmddj.mdid=SC&amp;_Bmddj.djid=BM&amp;_Bmddj.fid=200872&amp;_Bmddj.ver_i=v1&amp;_Bmddj.act_name=Act5&amp;_Bmddj.act_type=BOM信息录入&amp;_Bmddj.opr_flag=N&amp;_Bmddj.org_mdid=SC&amp;_Bmddj.org_djid=BM&amp;_Bmddj.act_flag=A&amp;_Bmddj.flw_flag=&amp;_Bmddj.mdid_opr_flag=*" style="height: 458px;"></iframe>

iframe中包含iframe,但src有些不同,可以使用如下方法:

        print('//*[@id="layui-layer-iframe2"]')
        iframe4 = iframe = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH,"//iframe[contains(@src, '/PublicArea/Public/')]")))
        # 根据iframe的src内容来切换不同的iframe
        self.driver.switch_to.frame(iframe4)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值