Cannot click WebElement that is outside visible area of browser in Chrome

6,430 views
Skip to first unread message

Iain Rose

unread,
Mar 3, 2012, 12:37:48 AM3/3/12
to webd...@googlegroups.com
Hello everyone,

I have a problem using WebDriver with Java and Chrome on a Mac.

I need to test pages with tables that contain more rows than can be displayed on the screen at once.

What I want to do is define a WebElement that represents a checkbox in a row that could be at the bottom of the table and click it. However, I'm finding that if the checkbox (or a link for that matter) requires the browser to scroll down to display it, the click command is not working. I can interact with the element while it's off screen and get the value of isSelected() for example but cannot click it.

To get around this I'm having to add some really dirty hacks, such as the one below which repeatedly attempts to click the checkbox and scroll down the page until it is finally selected. Not pretty but at least it works for now.


        WebElement usersCheckBox = driver.findElement(By.id(id));

        while (usersCheckBox.isSelected()==false)
        {
            driver.findElement(By.tagName("body")).sendKeys(Keys.ARROW_DOWN);
            usersCheckBox = driver.findElement(By.id(id));
            usersCheckBox.click();
        }

I've tried this with Chrome Driver v8.0.995.0 & v8.0.1022.0.
I've also seen this with Selenium-Java 2.19 & 2.20.

Is anyone else seeing this issue? 

Iain

Mark Collin

unread,
Mar 5, 2012, 1:16:39 AM3/5/12
to webd...@googlegroups.com

It is y design that you cannot click on something that is not visible.

 

That being said, WebDriver should be scrolling things that are off screen into view so that they can be clicked upon.

 

I wonder if you have found an instance where you have to scroll left/right to bring the element on screen and WebDriver is not able to perform a left/right scroll, only an up down one…

 

(All pure guesswork, but you never know)

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


-- This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error please notify postm...@ardescosolutions.com

Iain Rose

unread,
Mar 7, 2012, 1:44:35 PM3/7/12
to webd...@googlegroups.com
I think that's the issue, is this a ChromeDriver or a WebDriver bug? 

Anthony Hallett

unread,
Mar 7, 2012, 9:38:18 PM3/7/12
to webdriver
Another hack which is a bit more generic, is to add your own
scroll_into_view method to Watir::Element using the javascript
scrollIntoView method:

class Watir::Element
   def scroll_into_view
    assert_exists
    begin
      driver.execute_script("arguments[0].scrollIntoView(true);",
@element)
    rescue Exception => ex
       puts "scrollIntoView error: #{ex.message}"
       puts "Status: #{browser.status}"
    end
  end
end

On Mar 8, 5:44 am, Iain Rose <iain.r...@gmail.com> wrote:
> I think that's the issue, is this a ChromeDriver or a WebDriver bug?
>
> On Sun, Mar 4, 2012 at 10:16 PM, Mark Collin <m...@ardescosolutions.com>wrote:
>
>
>
>
>
>
>
> > It is y design that you cannot click on something that is not visible.****
>
> > ** **
>
> > That being said, WebDriver should be scrolling things that are off screen
> > into view so that they can be clicked upon.****
>
> > ** **
>
> > I wonder if you have found an instance where you have to scroll left/right
> > to bring the element on screen and WebDriver is not able to perform a
> > left/right scroll, only an up down one…****
>
> > ** **
>
> > (All pure guesswork, but you never know)****
>
> > ** **
>
> > *From:* webd...@googlegroups.com [mailto:webd...@googlegroups.com] *On
> > Behalf Of *Iain Rose
> > *Sent:* 03 March 2012 05:38
> > *To:* webd...@googlegroups.com
> > *Subject:* [webdriver] Cannot click WebElement that is outside visible
> > area of browser in Chrome****
>
> > ** **
>
> > Hello everyone,****
>
> > ** **
>
> > I have a problem using WebDriver with Java and Chrome on a Mac.****
>
> > ** **
>
> > I need to test pages with tables that contain more rows than can be
> > displayed on the screen at once.****
>
> > ** **
>
> > What I want to do is define a WebElement that represents a checkbox in a
> > row that could be at the bottom of the table and click it. However, I'm
> > finding that if the checkbox (or a link for that matter) requires the
> > browser to scroll down to display it, the click command is not working. I
> > can interact with the element while it's off screen and get the value of
> > isSelected() for example but cannot click it.****
>
> > ** **
>
> > To get around this I'm having to add some really dirty hacks, such as the
> > one below which repeatedly attempts to click the checkbox and scroll down
> > the page until it is finally selected. Not pretty but at least it works for
> > now.****
>
> > ** **
>
> > ** **
>
> >         WebElement usersCheckBox = driver.findElement(By.id(id));****
>
> > ** **
>
> >         while (usersCheckBox.isSelected()==false)****
>
> >         {****
>
> > driver.findElement(By.tagName("body")).sendKeys(Keys.ARROW_DOWN);****
>
> >             usersCheckBox = driver.findElement(By.id(id));****
>
> >             usersCheckBox.click();****
>
> >         }****
>
> > ** **
>
> > I've tried this with Chrome Driver v8.0.995.0 & v8.0.1022.0.****
>
> > I've also seen this with Selenium-Java 2.19 & 2.20.****
>
> > ** **
>
> > Is anyone else seeing this issue? ****
>
> > ** **
>
> > Iain****
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "webdriver" group.
> > To post to this group, send email to webd...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > webdriver+...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/webdriver?hl=en.****
>
> > -- This message contains confidential information and is intended only for
> > the individual named. If you are not the named addressee you should not
> > disseminate, distribute or copy this e-mail. Please notify the sender
> > immediately by e-mail if you have received this e-mail by mistake and
> > delete this e-mail from your system. If you are not the intended recipient
> > you are notified that disclosing, copying, distributing or taking any
> > action in reliance on the contents of this information is strictly
> > prohibited. If you have received this email in error please notify
> > postmas...@ardescosolutions.com

Iain Rose

unread,
Mar 14, 2012, 2:01:17 PM3/14/12
to webd...@googlegroups.com
Thanks, I'll give that a try. Have you seen this issue too?

My solution so far was to just exclude those tests from the Chrome testsuite and only run the tests in Firefox.
> > For more options, visit this group at
> >http://groups.google.com/group/webdriver?hl=en.****
>
> > -- This message contains confidential information and is intended only for
> > the individual named. If you are not the named addressee you should not
> > disseminate, distribute or copy this e-mail. Please notify the sender
> > immediately by e-mail if you have received this e-mail by mistake and
> > delete this e-mail from your system. If you are not the intended recipient
> > you are notified that disclosing, copying, distributing or taking any
> > action in reliance on the contents of this information is strictly
> > prohibited. If you have received this email in error please notify
> > postmas...@ardescosolutions.com
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "webdriver" group.
> > To post to this group, send email to webd...@googlegroups.com.
> > To unsubscribe from this group, send email to

Sanam Chugh

unread,
Mar 4, 2013, 11:35:23 PM3/4/13
to webd...@googlegroups.com
Hi,

    I am facing this same issue. My button is not visisble.Once we scroll down the button would be seen.If I click when the button is not visible, the click is performed but there is no outcome.I am using webdriver. Selenium 2.25

Thanks,
Sanam
> > For more options, visit this group at
> >http://groups.google.com/group/webdriver?hl=en.****
>
> > -- This message contains confidential information and is intended only for
> > the individual named. If you are not the named addressee you should not
> > disseminate, distribute or copy this e-mail. Please notify the sender
> > immediately by e-mail if you have received this e-mail by mistake and
> > delete this e-mail from your system. If you are not the intended recipient
> > you are notified that disclosing, copying, distributing or taking any
> > action in reliance on the contents of this information is strictly
> > prohibited. If you have received this email in error please notify
> > postmas...@ardescosolutions.com
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "webdriver" group.
> > To post to this group, send email to webd...@googlegroups.com.
> > To unsubscribe from this group, send email to

Mike Riley

unread,
Mar 6, 2013, 12:40:36 PM3/6/13
to webd...@googlegroups.com
Sanam,

WebDriver should automatically scroll to where the element is you are interacting with.  If you can provide example code showing this you can file an issue.  You would need to provide an example page and the Selenium code to cause the error to happen.

You might want to watch the browser as your code runs.  I like to single step through a section giving me a problem to verify that it is not my code that is the cause, while I watch what is done in the browser.

Mike

Praveen Verma

unread,
Nov 9, 2016, 9:19:35 PM11/9/16
to webdriver
I am also facing the same issue to scroll

    public void openWebsite() throws Exception {
        myChrome.Chrome("http://seleniumeasy.com/selenium-tutorials/test-data-in-automation-framework");
        Thread.sleep(5000);
        JavascriptExecutor jse = (JavascriptExecutor)driver;
        jse.executeScript("scroll(0, 250),");

On Mac chrome browser not able to scroll getting error

java.lang.NullPointerException
    at TestCases.TestCases.openWebsite(TestCases.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1137)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:753)
    at org.testng.TestRunner.run(TestRunner.java:607)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:363)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:321)
    at org.testng.SuiteRunner.run(SuiteRunner.java:270)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
    at org.testng.TestNG.runSuites(TestNG.java:1124)
    at org.testng.TestNG.run(TestNG.java:1096)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

Thanks Praveen

⇜Krishnan Mahadevan⇝

unread,
Nov 10, 2016, 1:25:44 AM11/10/16
to webdriver
Praveen,

This doesn't look like its a problem with Selenium Webdriver.
The fact that you are seeing a NullPointerException indicates that there's a problem in your test code.

The stacktrace you shared is NOT complete and hence we cannot help identify what in your test code is causing this.

You would need to share the complete test code and the complete stacktrace !

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+unsubscribe@googlegroups.com.

To post to this group, send email to webd...@googlegroups.com.

Bill Ross

unread,
Nov 10, 2016, 1:59:32 AM11/10/16
to webd...@googlegroups.com

The most obvious possibilities for nulls are myChrome and driver:

  myChrome.Chrome("http://seleniumeasy.com/selenium-tutorials/test-data-in-automation-framework");

  JavascriptExecutor jse = (JavascriptExecutor)driver;
  jse.executeScript("scroll(0, 250),");

But this is just basic debugging, as Krishnan says it's unrelated to webdriver. You should be aware how to look at TestCases.java:22 and reason what is null and why; hopefully the above should get you started.

Bill
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages