Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer exception when calling webDriver.findElements #4555

Closed
ClintonMorrison opened this issue Aug 23, 2017 · 11 comments
Closed

Null pointer exception when calling webDriver.findElements #4555

ClintonMorrison opened this issue Aug 23, 2017 · 11 comments

Comments

@ClintonMorrison
Copy link

Meta -

OS: OSX
Selenium Version: 3.3.1, IntelliJ
Browser: Chrome 60

Browser Version:
Version 60.0.3112.90 (Official Build) (64-bit)

Expected Behavior -

No null pointer exception when calling webDriver.findElements

Actual Behavior -

Occasionally, calling webDriver.findElements(By.cssSelector(query)) causes a null pointer exception. Here is the stack trace:

java.lang.NullPointerException
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:450)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementsByCssSelector(RemoteWebDriver.java:509)
    at org.openqa.selenium.By$ByCssSelector.findElements(By.java:441)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:402)
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.remote.Augmenter$CompoundHandler.intercept(Augmenter.java:189)
    at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$88202d8c.findElements(<generated>)

Steps to reproduce -

It seems to happen only rarely happen so it's hard to reliably reproduce. I think it is a race condition. There was a recently a report of a similar issue in: #4375

@barancev
Copy link
Member

Actually, it's a chromedriver issue. It must return a list of web elements (or an empty list) on this operation. But sometimes it breaks the contract and returns null. Sigh

So we have to be more defensive and convert null to an empty list on the client side. All language bindings can suffer from this issue.

@barancev
Copy link
Member

Fixed in Java binding by 4a3ec2d

@barancev barancev removed the C-java label Aug 24, 2017
@ClintonMorrison
Copy link
Author

Thanks @barancev!

@ClintonMorrison
Copy link
Author

What release will this be in?

@p0deje
Copy link
Member

p0deje commented Aug 31, 2017

Fixed in Ruby bindings in d4d8433.

@p0deje p0deje removed the C-rb label Aug 31, 2017
@lmtierney
Copy link
Member

Does this only affect findElements and not findChildElements?

@lmtierney
Copy link
Member

Fixed in python 4fcce6e

@lmtierney lmtierney removed the C-py label Sep 1, 2017
Tom-Trumper pushed a commit to Tom-Trumper/selenium that referenced this issue Sep 11, 2017
Tom-Trumper pushed a commit to Tom-Trumper/selenium that referenced this issue Sep 11, 2017
Tom-Trumper pushed a commit to Tom-Trumper/selenium that referenced this issue Sep 11, 2017
jleyba added a commit that referenced this issue Oct 6, 2017
@jleyba jleyba removed the C-nodejs label Oct 6, 2017
@IvantsovAV
Copy link

IvantsovAV commented Nov 8, 2017

A moment ago (but don't reproduce):

InternetExplorerDriver server (32-bit) 3.6.0.0
selenium-java 3.7.1

java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.util.Optional.<init>(Optional.java:96) at java.util.Optional.of(Optional.java:108) at java.util.stream.FindOps$FindSink$OfRef.get(FindOps.java:193) at java.util.stream.FindOps$FindSink$OfRef.get(FindOps.java:190) at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:881) at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:43) at org.openqa.selenium.support.ui.ExpectedConditions$20.apply(ExpectedConditions.java:579) at org.openqa.selenium.support.ui.ExpectedConditions$20.apply(ExpectedConditions.java:575) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)

Maybe it returns list of null(s)?

@BrandonDudek
Copy link

In Selenium 3.14.0, I see cases where response is returning an empty string as the value.
Can this case be covered as well?

BrandonDudek added a commit to BrandonDudek/swatt that referenced this issue Aug 17, 2018
…lementWrapper

RestResponse
- Added Class.

WebDriverWrapper
- Added BrowserType enum.
- Added BROWSER_TYPE constant.
- Added workaround for Bug: Null pointer exception when calling webDriver.findElements #4555 <SeleniumHQ/selenium#4555>.

WebElementTransitionalWrapper
- Added constructor for that takes in a WebElementWrapper.

WebElementWrapper
- Added controlCommandClick(), doubleClick(), keyClick(CharSequence), and getCssValue(String _propertyName), rightClick(), &
rightClickAndSelectContextMenuItem(int) methods.
- Added ReAcquire chatch to all "Perform Actions" calls.

v1.3.0-SNAPSHOT
@diemol
Copy link
Member

diemol commented May 21, 2020

It seems it was implemented in all bindings except .NET, in case any one finds an issue there, please open a new issue.

@diemol diemol closed this as completed May 21, 2020
@sushmanarla
Copy link

The problem for me was that the path to find chrome browser was missing ".exe" in it. I'm referring to the "VM options:" in Run>Edit Configurations>JDK Settings

-Dwebdriver.chrome.driver="D:\Work\Softwares\chromedriver_win32.\chromedriver.exe"

@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants