I would like to select a button with selenium on the net, here’s the HTML code of the button:
JavaScript
x
4
1
<button type="button" ng-if="grid.appScope.edit_column" ng-click="grid.appScope.executeActionButtonEvent(row, grid.appScope.edit_column, grid['options'])" class="btn btn-default ng-scope" aria-label="Left Align">
2
<span class="glyphicon glyphicon-edit glyphicon-align-left" aria-hidden="true"></span>
3
</button>
4
They are 1 to 5 and have all the same XPATH : //html/body/div[2]/div/section/section/div[1]/div/div[2]/div[1]/div[2]/div[2]/div/div[2]/div/div[1]/div/button[1]
How can I select the third or second button with no tag in the HTML code?
Advertisement
Answer
JavaScript
1
2
1
driver.find_elements_by_xpath("//html/body/div[2]/div/section/section/div[1]/div/div[2]/div[1]/div[2]/div[2]/div/div[2]/div/div[1]/div/button[1]")[2]
2
You can use find_elements instead of find_element. Then you can get the 2. index of the result.