Irina Irina - 9 months ago 32
Ruby Question

How to find a css element on the page if it is display: none?

I'm running automated testing in Ruby.

I'm trying to write a script that finds id with

(visible only in mobile form), and clicks it.

Here is my code:

def open_menu
page.find[:css, "a[id='mobile-nav-link']", visible: false].click

It gives me an error:

invalid selector: No selector specified

Answer Source

A quick search reveals similar code using round brackets, not square. I.e.:

def open_menu
   page.find(:css, "a[id='mobile-nav-link']", visible: false).click