1

My html code is :

<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>

I tried:

1. find(:xpath, "//span[@class='sr-only']").click


2. page.find('.sr-only',visible: false).click

but was not able to find element 'sr-only'. How to find it?

Exception I got is:

Selenium::WebDriver::Error::ElementNotVisibleError:
   element not visible

Note Using chrome webdriver + selenium

vidal
  • 345
  • 3
  • 18

1 Answers1

3

By default Capybara doesn't find non-visible elements (which anything with a class of 'sr-only' usually is), and even when you tell it find non-visible elements (through the visible: false (or :hidden/:all) option) you won't be able to click on the element because there would be no way for a user to click on a non-visible option. It seems like you want to click on the close button, so if you're using Capybara 2.10+ you should be able to do

click_button(class: 'close')

if using an older Capybara you should be able to do

find('button.close').click
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78