BERLIN (Reuters) - Germany cleared the way for its giant automotive industry to develop and test self-driving cars, when the upper house of its parliament approved on Friday a law setting out the conditions under which they could take to German roads.

Under the law, first mooted by Chancellor Angela Merkel last year, a driver must be sitting behind the wheel at all times ready to take back control if prompted to do so by the autonomous vehicle.

Germany is home to some of the world's largest car companies, including Volkswagen VOWG_p.DE, Daimler and BMW, all of which are investing heavily in a technology seen by transport minister Alexander Dobrindt as the "greatest mobility revolution since the invention of the car".

The new legislation allows them to road-test vehicles in which drivers will be allowed to take their hands off the wheel and their eyes off the road to browse the web or check e-mails while the vehicle handles steering or braking autonomously.

The legislation requires that a black box record the journey underway, logging whether the human driver or the car’s self-piloting system was in charge at all moments of the ride. This will be crucial for apportioning blame in accidents.

The driver will bear responsibility for accidents that take place under his or her watch, under the legislation, but if the self-driving system is in charge and a system failure is to blame, the manufacturer will be responsible.

The law will be revised in two years’ time in the light of technological developments, with data protection and the use of the data collected during rides a key point that has yet to be fully addressed.

Companies around the globe are working on prototypes for self-driving vehicles, but such cars are not expected to be available for the mass market before 2020.