3

I want to click web element inside the iframe and trying to switch to respective iframe before clicking to web element. browser.switchToFrame(number) - switch to iframe with number is working but unable switch to iframe with css selector.

I have tried below code.

 await $('.framed_view').waitForDisplayed({ timeout: 5000 });
 const iframe = $('.framed_view');
 await browser.switchToFrame(iframe);
Vaibhav Jagdale
  • 229
  • 2
  • 11

2 Answers2

0

Because it only accepts ID of the element. This method doesn't work the same way as usual $ calls.

See: webdriver.io/docs/api/jsonwp/#switchtoframe

Tbh, I had issues with switching to frames via this or similar wdio methods myself and never managed to get it working.

Maverick
  • 61
  • 1
  • 5
  • I was checking few solution on stack overflow and blogs but hard luck for me. https://stackoverflow.com/questions/65864821/how-to-handle-iframe-content-using-webdriverio-js-and-mocha https://stackoverflow.com/questions/54799479/webdriverio-5-how-to-switch-to-iframe-when-its-element-id-not-given https://chercher.tech/webdriverio/iframes#handle-frames-webdriverio – Vaibhav Jagdale Aug 08 '22 at 14:23
0

You can also use xpath to select Iframe. This worked for me

get mainFrame() {
    return $("//devsite-iframe/iframe");
}
async switchFrame () {
    await this.mainFrame.waitForExist({ timeout: 3000 });
    await browser.switchToFrame(await this.mainFrame); 
}