Skip to content
Advertisement

Selenium 4 : frameToBeAvailableAndSwitchToIt doesn’t seem to work

I am trying to work with a webpage in Selenium 4. The page has a few iframes and I am trying to wait for an iframe to load completely and then switch to it.

However, the code below doesn’t seem to work:

JavaScript

The system out just prints an empty HTML snippet below:

JavaScript

As a result, when I try to select any element after the switch, it fails. The iframe is loading alright in the chrome window which seems strange to me. I have tried implicit wait as well which did not work and had the same result.

After a few hours of debugging, I have not been able to identify the root cause. Any help is much appreciated.

Best, R

Advertisement

Answer

I’ve reproduced the issue.

This behavior looks like a selenium bug, because, when it switches to frame, the frame has no any product elements (they are loaded a few seconds later). But then, when I was in debug and all the products loaded, and a I call driver.getPageSource(), the result is <html><head></head><body></body></html>, and when I call this again, it loads the correct page source, but still the driver cannot find any element inside the iframe.

So, I’ve added a custom expected condition, which switches to frame and check if some element present for workaround this.

JavaScript
Advertisement