双击嵌套在其他ifram中的iframe中的WebElement

2024-10-01 02:18:40 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,我的页面有以下规范:

<html>
   ...
   <iframe id="lvl1">
       <html>
           <iframe id="lvl2">
               <div>Double Click Me !</div>
           </iframe>
       </html>
   <iframe>
</html>

我无法双击给定的元素(使用ActionChain),因为当我执行时,会抛出一个moveTargetOutboundsException。在

^{pr2}$

我基于上一个发布的评论here上一个片段。在


Tags: div规范id元素html页面meclick
1条回答
网友
1楼 · 发布于 2024-10-01 02:18:40

在上面的链接中发布的方法实际上是一个很好的方法。我当前选择的帧不是第n-1帧,我需要显式引用第n帧(我的元素所在的帧)

location = (element.location['x'] + element.size['width'] / 2, element.location['y'] + element.size['height'] / 2)

#Switching to the n-1 th frame, frames is an array of frames' name
frames = page.frame

browser.switch_to_default_content()
for frameName in frames[:len(frames) - 1]:
    browser.switch_to_frame(frameName)

#Handle to the n th frame
frame = browser.find_element_by_tag_name(name="iframe")
action = ActionChains(context.browser)
action.move_to_element_with_offset(frame, location[0], location[1]).double_click()
action.perform()

相关问题 更多 >