Check your garage door opener manual for a trouble-shooting procedure which may help figure out where the problem really is. It certainly could be just the sensor. Having had a bizarrely behaving garage door which turned out to be the main "computer" board in the opener, I'd want to try and check that the sensor was getting whatever it needed to operate correctly before I'd assume that the sensor was the cause of the sensor not working and bought a new one. If, for instance, the main unit is not supplying power to the sensor, replacing the sensor won't fix it. Your manual may provide some procedures to test/isolate the problem.
More generally, my advice (despite the fact that I did replace that main board for a successful repair) is always to consider the age of the unit and the price of a replacement. Parts are often not returnable and don't have any warranty, while a whole new unit comes with a whole new warranty. In my case I bet that the board, at about half the cost of the relatively new opener would do it, as I knew there had been a nearby lightning strike. With an older unit, I'd lean heavily to replacement to avoid replacing so many parts trying to solve the problem that I'd have spent less for a complete new opener.
To be clear, I have no idea where your actual problem is, but it could be:
- The sending unit
- The receiving sensor unit
- Or the main unit powering both units and reading the sensor output
- Or the wires connecting them may be broken.
If your garage has mice as most do, that last one might be the first one to check.