1

If I run my scripts without first waiting for the element it moves to quickly and fails because the item is not available. The page I'm interacting with is HTML5/Angular. My questions is - is there a more efficient way to wait for an item, then click it? What I'm doing below works great but having to wait, then click, then wait for the next thing, then click over and over doesn't seem like the best way.

Setup:

def wait_for(timeout = 55)

    Selenium::WebDriver::Wait.new(:timeout => timeout).until { yield }

end

def displayed?(how, what)

    @driver.manage.timeouts.implicit_wait = 55

    @driver.find_element(how, what).displayed?

end

Execution:

 wait_for { displayed?(:xpath, "//div[text() = 'Previous Year']") }

 @driver.find_element(:xpath, "//div[text() = 'Previous Year']").click  
1
  • 1
    To be honest with you, your solution is possibly the best bet. One of the first things I wrote when I started with WebDriver was a quick little 'wait for and click' function similar to your own. I'm not too familiar with the Ruby bindings but if you're not using an explicit wait, use that instead of the implicit wait. Commented Jan 20, 2016 at 17:15

1 Answer 1

1

We encountered a similar problem with QA scripts and our solution was to hide elements (ng-hide) until the controller and services finished all their work. I think your problem is that the Angular view code is probably all visible while building and populating, so Selenium passes the display check, but can't actually use it yet. Better for QA to keep it hidden until functional.

Sign up to request clarification or add additional context in comments.

1 Comment

So I think you're totally right on the Angular all visible but not usable. However, I'm going to have to find a way around this myself, dev certainly isn't going to make any changes for me in that respect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.