A 13-year-old boy who had researched school shootings online was arrested hours after he tried to enter a Wisconsin elementary school while armed and then fled when confronted by school staff, police said.