Home > Software design >  Click on HTML button throw a Uncaught TypeError: Cannot read properties of null (reading 'lengt
Click on HTML button throw a Uncaught TypeError: Cannot read properties of null (reading 'lengt

Time:10-12

I'm quite a JS nob and this might be a very stupid question.

Via the chrome dev tool console, I'm trying to click on a "show more" button that I have on the page I'm visiting (https://www.capterra.com/account-based-marketing-software/):

document.getElementsByClassName('Button__CenteredText-sc-2779at-4')[0].click();

The click loads more results into the page and that is what I would expect.

However, as soon as the line of code runs, the console throws a:

Uncaught TypeError: Cannot read properties of null (reading 'length')
at forEach (/directoryPage/assets/webpack:/src/ui/app/gtm-client.js:32)
at Array.forEach (<anonymous>)
at initializePayload (/directoryPage/assets/webpack:/src/ui/app/gtm-client.js:31)
at Object.transmitToDataLayer (/directoryPage/assets/webpack:/src/ui/app/gtm-client.js:48)
at /directoryPage/assets/webpack:/src/ui/app/components/PageContainer/LayoutContainer.js:260

I have tried to wrap my click call around a try..catch, but the error keeps popping up.

Does anyone have any idea about the possible cause for this error?

Thanks! Alessio

CodePudding user response:

The error shown in the console seems not to be related to the line of code that you posted. Try to put a breakpoint in the line where forEach is executed to see why the value is null.

  • Related