2

TypeError: elem[prop] is not a function

E2E testing in webdriveio. I want to click a button inside an iframe.

let iframe = browser.$('#fullmessage')
        browser.pause(1000)
        browser.switchToFrame(iframe)
        browser.setTimeout({ implicit: 10000 })
        let clickAgree = $('a[class="button is-success"]')
        clickAgree.click()
        browser.switchToParentFrame()
        browser.pause(3000)
Zach Jensz
  • 3,650
  • 5
  • 15
  • 30
Amer Gaber
  • 21
  • 1
  • 3

2 Answers2

2

Hi i faced with the same problem, but in async. The reason is that you need to await already defined element as parameter: get iframe() { return $('.iframe'); }

await browser.switchToFrame(await this.iframe); Because switchToFrame works only with element, not with promise. Maybe for someone it will be useful.

1

I was facing same error and when debug more using REPL found that the issue could be due to 2 reasons:

  1. selector is returning array of elements and so it was not able to call the method used.
  2. the method being called on element does not supports.

For example with following code:

$('.some_class').$$('input').getValue();

was getting error - Uncaught Error: elem[prop] is not a function. Using $('.auto_test_class').$$('input')[1].getValue(); works. But its better to use some Id or xpath.

Hope this might be useful for someone facing same issue :)

Sajal
  • 1,198
  • 1
  • 17
  • 32