1

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?

mziemer
  • 338
  • 3
  • 13
  • What if you pass `easyXDM_1435765828615` string into `switchToFrame()`? Or, is the id dynamically generated? – alecxe Jul 01 '15 at 17:07
  • It is dynamic. Currently I am using an xpath //*[contains(@id,"easyXDM_")] to find the iframe. – mziemer Jul 01 '15 at 17:17
  • Okay, another option: specify the index of the form - e.g. `switchToFrame(1)`. – alecxe Jul 01 '15 at 17:18
  • It just times out when I pass element.elementId or 1. Side note element.elementId = 15, but my original code errors with element: 16?? – mziemer Jul 01 '15 at 17:47

1 Answers1

0

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.

Tyler
  • 740
  • 9
  • 27