HashNuke / hound

Elixir library for writing integration tests and browser automation

Home Page:http://hexdocs.pm/hound

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use custom ResponseParser?

onelesd opened this issue · comments

The warning below is printed when an element is found on the page and is visible, but it's position shifts due to a changing DOM before the click() is executed.

find_element({:xpath, "//span"})
|> click()
16:33:06.734 [warn]  unknown error: Element <span>...</span> is not clickable at point (1153, 90). Other element would receive the click: <div></div>
  (Session info: chrome=63.0.3239.132)
  (Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.2 x86_64)

No exception is raised (unlike a click() of an element that is not visible, which raises "element is not visible"), so there is no way to catch this error and try again.

A kludge is to sample the element's location N times before attempting the click, but we still have a race condition that is prone to breakage.

Is there another technique?

I see that warning?/1 is defoverridable in Hound.ResponseParser, which I would have raise the exception. It seems to be hard-coded based on the selected driver here:

defp response_parser do
{:ok, driver_info} = Hound.driver_info
case driver_info.driver do
"selenium" ->
Hound.ResponseParsers.Selenium
"chrome_driver" ->
Hound.ResponseParsers.ChromeDriver
"phantomjs" ->
Hound.ResponseParsers.PhantomJs
other_driver ->
raise "No response parser found for #{other_driver}"
end
end

How do I set a custom ResponseParser?

Hi, sorry for the delay.
The current implementation does not allow to set a custom parser. If you would like to send a PR to implement this, you are very welcome.
Thank you.