Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Ruby - Switch frame by class attribute

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>
like image 439
eladr Avatar asked Oct 15 '25 09:10

eladr


1 Answers

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.

like image 101
Mobrockers Avatar answered Oct 18 '25 03:10

Mobrockers