2

I want to use use wait_until method until visible for my element. Currently i am using Siteprism method which is as below. Which is a built in Siteprism method but looks like its not performing well as intermittently it is throwing error (Object not exist in the DOM).

@home.wait_until_btn_element_visible

So i want to use find method from capybara. Provably which is a better easiest solution. But i having trouble with defining css. As i am defining css in ruby class. I want to use that variable in to below code. How can i do that?

page.find('#blah').visible?.should be_true

I want something like this :

page.find(@home.btn_element).visible?.should be_true

Looks like it is not working rather throwing this error below:

invalid selector: An invalid or illegal selector was specified

Need help..... Or any other solution will be appreciated..

ASM
  • 709
  • 2
  • 8
  • 27

1 Answers1

1

#find takes a selector type and parameters of some type, it does not take an element from the page. Since (after a quick look at the source) it doesn't appear there is anyway to access the parameters specified in your element :btn_element, ... declaration from site_prism, there is no way for you to call #find without retyping the selector. That being said there really should be no difference between the @home.wait_until_btn_element_visible and what you state you want to do since site_prism ends up calling Capybaras find with visible: true specified. The only difference is that site_prism uses its own wait timeout, so you might want to try increasing SitePrism::Waiter.default_wait_time or specifying longer wait timeout in the wait_until_xxx call

@home.wait_until_btn_element_visible(10)
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • As i said, its throwing this error intermittently: stale element reference: element is not attached to the DOM – ASM May 24 '16 at 19:23
  • I can resolve it by rescue it and try again. But i don't like it. Need some other good solution /method – ASM May 24 '16 at 19:46
  • @ASM Yes -- but that error should only raise after the timeout occurs (try increasing the timeout) or potentially if your @home element is found using `#all` or `#first` in which case it can't auto reload itself and you should change how it was located. – Thomas Walpole May 24 '16 at 19:48
  • my element (btn_element) is actually elements and i tried wait for 60 secs also . Still it throws the error after 60 secs. But i can see that element in UI, page already loaded with that. – ASM May 24 '16 at 20:05
  • @ASM what is `@home` - is that from an element or elements definition, or is that a SitePrism::Page object? – Thomas Walpole May 24 '16 at 20:30
  • Its SitePrism::Page object. For element / elements both it throws "intermittent stale element error". I guess i need to use this: @results_page.wait_for_ :count => 25 from this link But i want to use "count > 25" . How can i do that? – ASM May 25 '16 at 15:39
  • @ASM You probably want to update your question because your requirements are changing. If what you actually want to do is wait for a certain number of elements to be on the page then you can pass any of capybaras quantity options (count, minimum, maximum, between) - so for more than 25 it would be `@reaults_page.wait_for_ minimum: 26` – Thomas Walpole May 25 '16 at 18:11
  • Same Error thrown for this as well: stale element reference: element is not attached to the page document – ASM May 25 '16 at 18:29
  • @ASM I think you need to re-ask/update your question - Your question talks about element but now your comments state you're looking for elements. What you asked for in your question (reusing selector from site_prism in straight capybara find) isn't possible. When you re-ask/update you should provide some of your code showing relveant parts of your page object declaration and your test code. – Thomas Walpole May 25 '16 at 18:33
  • I am getting error on both element / elements. I will add my code shortly – ASM May 25 '16 at 19:54