0

I'm trying to use browser.switchTo().frame(0) method in element.flood.io to switch between iFrames on a page. There are two iframes - xpath locations are //body[1]/form[3]/div[5]/iframe[1] and //body[1]/form[3]/div[2]/iframe[1]

I cant seem to interact with either frame on the page. So far I've tried :

step('3. Switch frame', async browser => {
        await browser.wait.Until.ableToSwitchToFrame()
        await browser.switchTo().frame(0)

I've tried using the xpath too.

step('3. Switch frame', async browser => {
        let iframe = await browser.findElement(By.xpath('//body[1]/form[3]/div[2]/iframe[1]'))
        let newbrowser = await browser.swicthto().frame(iframe)

This link is the which should be helpful but I do not find it to be:

https://element.flood.io/docs/api/browser#switchto

pavelsaman
  • 7,399
  • 1
  • 14
  • 32
KeithMc18
  • 112
  • 2
  • 10
  • 2
    Perhaps you don't mean Puppeteer? There's no such API method `switchTo()` (https://github.com/puppeteer/puppeteer/blob/v5.4.1/docs/api.md), and your link leads to Flood Element tool, which has nothing to do with Puppeteer apart from being it a JS tool as well. Some ideas to explore: are the iframe of the same domain as the page? is your xPath correct (it's so long, absolute, therefore likely to break). – pavelsaman Feb 01 '21 at 19:47
  • Hey @pavelsaman, the xpaths are correct and I edited the question to reflect that its not puppeteer although my error suggests otherwise. When you say are the iframes on the same domain, the iframe is on the same page but it is from a third party payment processor. I am now getting a new error `Error: Evaluation failed: DOMException: Blocked a frame with origin 'https://*' from accessing a cross-origin frame. at __puppeteer_evaluation_script__:2:77 at Array.find () at __puppeteer_evaluation_script__:2:57` – KeithMc18 Feb 02 '21 at 09:41
  • JavaScript can't access iframes from different origins, that's a cross origin access and that's forbidden by browsers since it could lead to a security risk. If this is the case (the error suggests so), you can't reach inside the iframe. – pavelsaman Feb 02 '21 at 10:03
  • This is very strange in my opinion. In another framework, Nightwatch.js, I can easily access this iFrame and interact with it as I need without any cross origin errors. This off topic but how can this be the case when both are JavaScript frameworks? – KeithMc18 Feb 02 '21 at 16:02
  • So just to elaborate, the iframe is a third party payment field, and if what your saying is true the framework is useless for testing any third party iframes. Is that correct? – KeithMc18 Feb 02 '21 at 16:11
  • 1
    Try it out in DevTools. If you can access some element inside the iframe, then you're only doing something wrong in Flood Element. If you can't, it's blocked and the iframe is only a blackbox for JS scripts from your site. – pavelsaman Feb 02 '21 at 18:00

1 Answers1

0

You can use:

await browser.wait(Until.ableToSwitchToFrame(frame id))

https://element.flood.io/docs/api/waiters#untilabletoswitchtoframeframe

Syscall
  • 19,327
  • 10
  • 37
  • 52