How to switch iframes InternJS

2019-06-01 09:07发布

I need to switch to an iframe that has a dynamic name and id.

<iframe name="easyXDM_1435765828615" id="easyXDM_1435765828615">...</iframe>

I noticed LeadFoot has a switchToFrame() function, but when I pass it an element that was returned from find() I get the error "MoveTargetOutOfBounds: POST http.../moveto / {"element":"16"} Offset within element cannot be scrolled into view".

Is there a better way to do this using execute() and some javascript, or how can I make switchToFrame() work?

1条回答
【Aperson】
2楼-- · 2019-06-01 09:48

Depending on how your iframes are setup on the page you could try something like this:

    .switchToFrame(null)
    .findAllByClassName('iframe')
    .then(
      function(iframes) {
         new remote.constructor(remote.session)
        .switchToFrame(iframes[iframes.length-1])
      }
    )

This assumes that the iframe you want to switch to is last to be found, which is obviously a big assumption. You might be able to tweak this though, if the dynamically created iframes appear in the same order every time.

查看更多
登录 后发表回答