1

Using TextAngular for a rich text input box in a AngularJS/ Rails environment.

Running integration tests with Capybara/Selenium & Capybara-Webkit. Tried to create an integration test that inputs text into the text area for a test. However, I have not been able to successfully do this.

The thing that has prevented me is the text input box id changes ever time the test loads or page loads. So I used the below class, which is used in the text angular tests. With:

find('textarea.ta-html.ta-editor')

I used this as i know it works and the javascript tests written for text angular used this. text angular github tests

However, when i try and set the text area with a text value:

find('textarea.ta-html.ta-editor').set("Upgraded to SSD")

I get:

Failure/Error: find('textarea.ta-html.ta-editor').set("Upgraded to SSD")
Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with

How can I set a value for the text area using Capybara?

4

1 回答 1

1

匹配的元素textarea.ta-html.ta-editor隐藏在页面上,而不是用户与之交互的元素。根据设计,Capybara 通常要求您与用户将与之交互的元素进行交互,因此您需要调用#set可见元素,该元素是您尝试与之交互和匹配的元素的前一个兄弟元素div[contenteditable]。您不显示您的 HTML,但希望您有一个可以限定范围的包含元素,以便您可以执行

find('<container_selector> div[contenteditable]').set(...)

或者

find('<more_general_container_selector>', text: '<label text or something else in the container>').find('div[contenteditable]').set(....)

如果您在页面上只有一个此类字段,您可能会侥幸逃脱

find('.text-angular div[contenteditable]').set('Upgraded to SSD')

注意:如果使用 selenium 驱动程序,它有一个限制,它只能与主要的 contenteditable 元素交互,而不能与在其中创建的子元素交互。我不确定其他水豚司机是否有同样的问题。

于 2016-04-12T03:19:49.033 回答