Selenium Ruby - Switch frame by class attribute

5.3k Views Asked by At

I'm using Selenium's Ruby bindings and I'm trying to make the WebDriver switch to an iFrame which is identifiable only by a class attribute.

Essentially I'm trying to achieve the equivalent of this Java code:
driver.switchTo().frame(driver.findElement(By.className("my-iframe-class")));
but I fail to do so since the Ruby wrapper only accepts id or name attributes in driver.switch_to.frame('some-id-or-name')

Any suggestions on how I can switch frame by class in Ruby?

Here's a sample HTML:

<html>
  <head></head>
  <body>
    <iframe class="my-iframe-class">
      <p>iframe body</p>
    </iframe>
  </body>
</html>
1

There are 1 best solutions below

2
On

The ruby docs on github say you can do:

driver.switch_to.frame driver.find_element(:class, 'some-frame') # frame element

Note that I have not used the ruby bindings so I cannot tell you if this is correct.