ferrum icon indicating copy to clipboard operation
ferrum copied to clipboard

Implement wait_for_selector

Open Mifrill opened this issue 3 years ago • 6 comments

closes #82

Mifrill avatar Jan 07 '22 00:01 Mifrill

Can this be merged? Do the linters need to be changed or do we want to follow the linter advice?

dsisnero avatar Mar 21 '22 15:03 dsisnero

Hello @dsisnero this PR is on review, it can't be merged without approval. The linter offenses are not related to this particular PR, we have dedicated PR to solve it: https://github.com/rubycdp/ferrum/pull/237 that also on review.

Mifrill avatar Mar 21 '22 18:03 Mifrill

I'm sorry guys, with all this stuff happening I barely find time for open source now, hope it's going to calm down soon.

route avatar Mar 21 '22 18:03 route

If anyone needs a simple substitute of assert_selector or Selenium::WebDriver::Wait.new.until &block and google leads him here, here is a simple ruby snippet to wait for arbitrary things to return true:

timeout_true = lambda do |timeout = 1, &block|
  Timeout.timeout timeout do
    block.yield or (sleep 0.1; redo)
  end
end

Nakilon avatar Jun 18 '22 14:06 Nakilon

Any chance we could have a reviewer review and accept this? It would be very nice to have in the main Gem.

Thanks!

shreeve avatar Nov 23 '22 06:11 shreeve

Would this be simpler?

class Ferrum::Browser
  def wait_for(want, wait:1, step:0.1)
    meth = want.start_with?('/') ? :at_xpath : :at_css
    until node = send(meth, want)
      (wait -= step) > 0 ? sleep(step) : break
    end
    node
  end
end

shreeve avatar Nov 23 '22 07:11 shreeve