In a vote that fell mostly along party lines, Republicans aimed to force vulnerable Democrats to take a stand ahead of the midterm elections.