我正在尝试切换到另一个ID为:“ ifrBetslipHolder”的iframe 有两个ID完全相同的iframe,但src不同
当我切换到iframe时,我总是会切换到第一个
如果我执行find_elements_by_id(“ ifBetslipHolder”),则仅返回一项
</span><span class="cIframeHolder" style="width: 355px; height: 433px;"><iframe scrolling="no" allowfullscreen="" class="cIframe" id="ifrBetslipHolder" name="ifrBetslipHolder" src="/fe/manager/blank.htm?bust=0.46149823458289685" style="width: 357px; height: 433px;" frameborder="no"></iframe><div class="winDragSurface" id="drag_winMan_19"></div></span></span><span class="winFrame" id="winMan_20" style="left: 550px; top: 150px; width: 369px; height: 472px; z-index: 57; display: block; visibility: visible;" closemode="1"><div class="winTrans" id="winBack_winMan_20" style=""></div><span class="winHeadbar" style="height: 30px;" id="winHead_0_winMan_20"><span class="winTitles"><span><span class="winTitleActive" panelid="winMan_20" id="winTitle_0_winMan_20">Ticket</span></span>
</span><span class="winControl" id="winControl_winMan_20"><span class="winConCls" id="winCls_winMan_20" winid="winMan_20" headerbtnid="undefined"></span><span></span></span>
</span><span class="cIframeHolder" style="width: 355px; height: 433px;"><iframe scrolling="no" allowfullscreen="" class="cIframe" id="ifrBetslipHolder" name="ifrBetslipHolder" src="/fe/manager/blank.htm?bust=0.4631218513461094" style="width: 357px; height: 433px;" frameborder="no"></iframe><div class="winDragSurface" id="drag_winMan_20"></div></span></span>
希望能够切换到ID为“ ifrBetslipHolder”的第二个iframe
答案 0 :(得分:0)
尝试以下逻辑。
driver.switch_to.frame(driver.find_element_by_xpath("(//iframe[@id='ifrBetslipHolder'])[2]"))
答案 1 :(得分:0)
HTML页面中的ID应该始终是唯一的。但是,许多浏览器和驱动程序都支持选择重复的ID。您可以使用其他方法,例如find_element_by_css_selector('#ifrBetslipHolder')[1]
。