Cannot read property 'setAttribute' of null

601 views
Skip to first unread message

Rupesh Patil

unread,
Dec 30, 2015, 12:27:12 PM12/30/15
to Selenium Users
public void HighlightWebElement(WebDriver driver, WebElement element) 
{
for (int i = 0; i <2; i++)
{
           JavascriptExecutor js = (JavascriptExecutor) driver;
           js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "border: 2px solid yellow;");  
          
           js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element);
       }
}
if some one have enough time can you please explain what is wrong with highlight line. Why I am getting following error.  

org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'setAttribute' of null
  (Session info: chrome=47.0.2526.106)
  (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.2 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'RP', ip: '192.168.56.1', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_80'
Session ID: 4abce27b86a082ab316676f0a9686797
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=WIN8, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\Rupesh\AppData\Local\Temp\scoped_dir2292_26716}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=47.0.2526.106, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504)
at ioh.utility.UtilityClass.HighlightWebElement(UtilityClass.java:24)
at ioh.main.ExecuteTestCases.test_HomePage_Elementes(ExecuteTestCases.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
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:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1246)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1171)
at org.testng.TestNG.run(TestNG.java:1066)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)

PeterJeffreyGale

unread,
Dec 30, 2015, 12:48:32 PM12/30/15
to Selenium Users
Where are you initiating the variable called "element" and how are you passing it to this routine? 


Rupesh Patil

unread,
Dec 30, 2015, 9:38:22 PM12/30/15
to seleniu...@googlegroups.com
Hello Peter,

I hope you are doing great. Thank you for your time, really appreciated 

In the following function I am passing element veritable.


@Test
public void test_HomePage_Elementes()
{
hashmap = new HashMap<String , List<String>>();
list = new ArrayList<String>();
Check_Home_Page_ homepage = PageFactory.initElements(driver, Check_Home_Page_.class);
hashmap = e.mapWithTestCases(con.WORKBOOKFILEPATH, con.WORKBOOKFILENAME,                            con.SHEETNAMEOFWORKBOOK);
WebElement element;
int presentcount=0;
int presentfailCount = 0;
for(int i = 1;i<hashmap.size();i++)
{
list = hashmap.get("STEP_0"+i);
try{
element = homepage.checkElementPresence(list.get(0).toString(), list.get(1).toString().trim(),                                  list.get(2).toString());
uti.HighlightWebElement(driver, element);
if(element.isDisplayed())
{
Reporter.log("<p align=\"left\">-( "+presentcount++ +" )--" + list.get(2).toString()+ " -----                                   PASS</p>");
}
else
{
uti.screenShort(driver, "test_HomePage_Elementes_"+list.get(2).toString());
Reporter.log(  "<p align=\"left\">----( "+presentfailCount++ +" )----- " +                                                           list.get(2).toString()+ " ----- FAIL</p>");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

On Wed, Dec 30, 2015 at 11:18 PM, PeterJeffreyGale <peterjef...@hotmail.co.uk> wrote:
Where are you initiating the variable called "element" and how are you passing it to this routine? 


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/sQ4aQBsKmIo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/5416c343-6e68-45ed-b1d1-e58974bc23cc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards,
Rupesh Patil,
(9970196189)

Peter Gale

unread,
Jan 2, 2016, 10:20:17 AM1/2/16
to seleniu...@googlegroups.com

In the preceding line, you seem to be setting that variable as a Boolean value rather than using findElement to set it to the element you want to highlight.

I think that is your problem.

Rupesh Patil

unread,
Jan 3, 2016, 5:20:37 AM1/3/16
to seleniu...@googlegroups.com
Hello Peter

Thank you Peter, Problem has been solve by your suggestion.
Thank you....


On Thu, Dec 31, 2015 at 2:39 PM, Peter Gale <PeterJef...@hotmail.co.uk> wrote:

In the preceding line, you seem to be setting that variable as a Boolean value rather than using findElement to set it to the element you want to highlight.

I think that is your problem.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/sQ4aQBsKmIo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages