ericmckean / chromedriver

Automatically exported from code.google.com/p/chromedriver
0 stars 0 forks source link

android - auto scroll to form element submit #982

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

If an input type submit is visible (command GET 
/session/:sessionId/element/:id/displayed returns true) but is not visible in 
the view (e.g : at the bottom of the page), the
exception "Element is not clickable at point (X, Y)" is throw.
From an end-user point of view, this is true because we need to scroll down in 
the page before clicking on it.

But scrolling to the element is not done automatically.
So we need to scroll manually to the element in the page.

For this, I have try :

- GET /session/:sessionId/element/:id/location_in_view : no success, location 
is returned but view not scroll
- POST session/:sessionId/touch/scroll : not implemented
- POST /session/:sessionId/moveto : of course, it didn't work (this is maybe 
the behavior expected so I'm not surprise)

So finally, a workaround is to get location of the element and then execute 
javascript to scroll to the element with :
  window.scrollBy(X, Y);

Tested with :

- android 4.4 Nexus 10
- chrome v39
- chromedriver 2.12

To reproduce it, just have a page within a form, a submit button not visible in 
the view (at the bottom of the page which need scroll), and just try to click 
on the button after being on the page (if you interact with some other inputs 
before like "input type text", view is scroll with keyboard and if element is 
near to the button, it could be clickable).

So I would be great if the element could be automatically scroll.

Thanks

Original issue reported on code.google.com by yannick....@gmail.com on 1 Dec 2014 at 1:14

GoogleCodeExporter commented 9 years ago
In fact, this bug occured not only for input type submit but also for some 
other elements like input type radio, input type checkbox, container (div), 
etc. I suspect that any elements which didn't have a "natural" focus by the 
browser (input type text with keyboard control, select) needs manual scroll 
with JS.

Original comment by yannick....@gmail.com on 2 Dec 2014 at 9:59

GoogleCodeExporter commented 9 years ago
OK, after some investigation, it seems that the keyboard controller is the 
troublemaker (not sure).

Here is a simple use case (sorry, but issue attachment storage quota is 
exceeded):

<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" version="XHTML+RDFa 
1.0" dir="ltr">
<head>
  <title>Test</title>
</head>
<body>

  <form action="/test.html" method="get">
    <div>

      <!-- no matter, it works with or without -->
      <div style="height:1500px;"></div>

      <!-- First element of that type do not use keyboard control? -->
      <input type="text" name="text" />

      <!-- no matter, it works with or without -->
      <div style="height:1500px;"></div>

      <!-- Twice to have keyboard control. If you remove it, all works. -->
      <input type="text" name="text_twice" />

      <!-- remove all of them and its work with keyboard control -->
      <div style="height:1500px;"></div>

      <input type="checkbox" name="checkbox" />

      <!-- remove all of them and its work with keyboard control -->
      <div style="height:1500px;"></div>

      <input type="radio" name="radios" value="foo" />
      <input type="radio" name="radios" value="bar" />
      <input type="radio" name="radios" value="baz" />

      <!-- remove all of them and its work -->
      <div style="height:1500px;"></div>

      <input type="submit" name="op" value="Submit" />
    </div>

  </form>

</body>
</html>

</code>

To reproduce :
- set value for the first input type text
- set value for the second type text (will show the keyboard control!)
- try to click on the checkbox (fail)
- try to click on a radio (fail)
- try to click on the submit button (fail)

if you don't set value for the second input type text, everything below is 
working fine.
If you remove fake container with heavy height (so all elements are visible on 
the same view), its works fine, even if you set values for both text input.

So to summarize, if you have a keyboard control displayed and element is not in 
the view (below), click events fail.

If we got the location of the checkbox before clicking on it, it returns (12, 
4560)
Or, the exception throw is : Element is not clickable at point (18, 705)

Original comment by yannick....@gmail.com on 9 Dec 2014 at 2:55

GoogleCodeExporter commented 9 years ago

Original comment by samu...@chromium.org on 21 Feb 2015 at 12:18