All elections by the people shall be by ballot or by any mechanical method prescribed by law. All election officers shall be sworn or affirmed not to disclose how any voter voted; provided, that in cases of contested elections, grand jury investigations and in the trial of all civil or criminal cases in which the violation of any law relating to elections, including nominating elections, is under investigation or at issue, such officers may be required to testify and the ballots cast may be opened, examined, counted, and received as evidence.