ScrollTo & Click to click element below "the fold".
Hound 1.0.4 ChromeDriver 2.32.498537 Elixir 1.5.1
We have a suite of tests that ran fine until I got a new smaller laptop and they suddenly started failing. I eventually figured out it is because the new laptop has a smaller screen resolution and the button was below the fold, resulting in the "Element not clickable at (x,y)" warning and subsequent checks failing.
I ended up with this little helper to help me scroll to the element I want to click on.
def scroll_click(element) do
{width, height} = element_location(element)
execute_script("window.scrollTo(#{width},#{height});")
click(element)
end
Is there a better way to do this? Can Hound have a native function to do this? How do other people deal with this?
I am having the same problem, but this solution doesn't seem to work for me. Would love to see a native solution.
I've been using the scroll_click ever since without any issues.
I couldn't use @Ivor's solution because on some of my app's pages scrolling happens within flexbox elements via overflow-y: scroll; rather than through native browser window scrolling.
Perhaps it's still possible to use JS to scroll within flexboxes, but instead I've been setting the window size prior to executing clicks. I have a MyApp.AcceptanceCase defined that gets used by individual test files, and it contains
Hound.start_session(opts)
Hound.Helpers.Window.set_window_size(
Hound.Helpers.Window.current_window_handle(),
1500,
3000
)
You may need to adjust the width & height values.