The first factories used water power (see the video below). Later this changed to steam power. Finally, it changed to electricity. It took about two centuries for this to happen, and the early stages from 1770 to about 1840 were called the Industrial Revolution.
The electricity is used to work machines. Here are some examples: In a clothes factory the machines sew pieces of cloth together. In a television factory the electricity may be used to work conveyor belts which carry the components of the television from one worker to the next. Electricity is used by robots in a car factory to assemble the body of a car.