简体   繁体   English

Webdriver.IO[7]:带有 css 选择器的 SwitchToFrame 不起作用

[英]Webdriver.IO[7] : SwitchToFrame with css selector is not working

I want to click web element inside the iframe and trying to switch to respective iframe before clicking to web element.我想单击 iframe 内的 web 元素并尝试切换到相应的 iframe,然后再单击 Z2567A5EC9705EB7AC2DZ98403 元素。 browser.switchToFrame(number) - switch to iframe with number is working but unable switch to iframe with css selector. browser.switchToFrame(number) - 切换到 iframe 与 number 工作但无法切换到 iframe 与 css 选择器。

I have tried below code.我试过下面的代码。

 await $('.framed_view').waitForDisplayed({ timeout: 5000 });
 const iframe = $('.framed_view');
 await browser.switchToFrame(iframe);

Because it only accepts ID of the element.因为它只接受元素的 ID。 This method doesn't work the same way as usual $ calls.此方法与通常的 $ 调用不同。

See: webdriver.io/docs/api/jsonwp/#switchtoframe请参阅: 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. Tbh,我自己通过这种或类似的 wdio 方法切换到帧时遇到了问题,但从未设法让它工作。

You can also use xpath to select Iframe.您也可以使用 xpath 到 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); 
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM