So, I was absolutely baffled as to how to do this in Selenium, and couldn\'t find the answer anywhere, so I\'m sharing my experience.
I was trying to select an ifram
You don't need to use JavascriptExecutor. All you needed to do was switch into the frame and then switch back out, like so:
// do stuff on main window
driver.switch_to.frame(frame_reference)
// then do stuff in the frame
driver.switch_to.default_content()
// then do stuff on main window again
As long as you are careful with this, you will never have a problem. The only time I always use a JavascriptExecutor is to get window focus since I think using Javascript is more reliable in that case.