If the battery light (which has the shape of a battery) lights up while driving, this means that the charging system itself does not work, but the fault of this malfunction might reside in something completely different from the battery.
Indeed, the cause may be a loose or corroded battery cable or other components of the charging circuit of the charging system, or it may be a problem with the alternator or with the voltage regulator. The alternator generates electricity that is accumulated in the battery. So, if the alternator does not work, or the service belt running the alternator is loose or broken, the battery is not recharged regularly or at all.
The battery itself may be the cause of the charging failure, eg if it is corroded at terminals, if it has damaged cells or plates inside or if the electrolyte is lost. In this case a corroded part cleaning and a battery voltage tester with a voltage level meter can provide some indication of whether the charging current normally comes from the alternator and therefore excludes it as a cause of the failure.
The charging system light should turn on for a few seconds when you start the car, but if it lights up while driving, it signals a problem. Among the other signals that the charging system does not work are the dim lights or the fact that the clock loses the correct indication of the time.
If the warning light comes on, you must come by a power tool or service center as soon as possible. In fact, the machine will continue to run until there is electricity in the battery, but if the charging system does not work, your car will stop working once the battery is exhausted. If you turn off the engine, you will not be able to restart it if the battery does not have enough residual left power to turn the starter motor.
If the warning light is on and you are still driving, turn off the largest number of electrical accessories, such as stereo, air conditioning or heating, and avoid using electrically operated controls such as power windows. Reducing the amount of electricity the car consumes will increase the distance for which you can drive before the battery is discharged. Go to a mechanic as quickly as possible to find out the cause of the problem.