Search code examples
selenium-webdriverrspeccucumbercapybarasite-prism

Wait until element is active/enabled to perform action(like click/select) on Siteprism Capybara?


In Siteprism i need to find out to wait for an element to be enabled before performing any action like click/select.

currently i am using this by Siteprism:

@page.wait_for_page_element(10)

But looks like that's not enough waiting. Still my script fails as the element was visible but not enabled. Need a solution.


Solution

  • You don't show how you've defined the element - but I assume you just did something like element :page_element, '#my_page_element' - The problem with this is it doesn't give any indication that the element is a actually a field and doesn't allow for using any of the field matching filters. If instead you define the element as

    element :page_element, :field, '#my_page_element'
    

    Then I believe calling wait_for_page_element on it will actually wait for it to be enabled since Capybara finds only enabled fields by default. If it doesn't or if you want to wait for a disabled field to be on the page then you can pass filter options (disabled, checked, readonly, etc) to wait_for_page_element

    @page.wait_for_page_element(10, disabled: false)