Capybara error: Selenium :: WebDriver :: Error :: ElementNotVisibleError: element is invisible

I am using Trix WYSIWYG editor in my application. For my capybara test: I want to populate an editor.

I found an article: How to check the basecamp disable editor ... which seemed promising. Unfortunately it keeps giving me this error:

Selenium :: WebDriver :: Error :: ElementNotVisibleError: Element is not visible

So it seems that Capybara finds the ok element, but it just doesn't interact with it, because Capybara must have some default settings to not interact with hidden / invisible elements.

Looking around I came across this Stackoverflow question: Is it possible to interact with hidden elements with capybara .

From this post: I've already tried this:

def fill_in_trix_editor(id, value)
  Capybara.ignore_hidden_elements = false
  find(:xpath, "//*[@id='#{id}']").set(value)
  Capybara.ignore_hidden_elements = true
end

      

Besides:

def fill_in_trix_editor(id, value)
  find(:xpath, "//*[@id='#{id}']", visible: false).set(value)
end

      

Any idea on how I can get Capybara to fill the editor? For what it's worth: I use rails 5.1.1

andchromedriver=2.29.461585

+3


source to share


1 answer


Short answer: you can't use selenium

Longer answer: This error is selenium preventing interaction with the invisible element because the user will not be able to click or send keys to the invisible element.

If you really want to change the value of the hidden element, the only way to use JS is through execute_script

, but most likely it will not generate the pending / using event trigger. The best solution would be to figure out which visible elements the user will interact with and interact with directly. Capybara with selenium supports calling set

on visible content elements that appear to use trix (along with custom elements), something like



find(:css, 'trix-editor').set("New text") 

      

will probably work for you

+3


source







All Articles