title: How to uniquely identify buttons using Xpath if the elements like 'id', 'class', 'type', 'value' and 'name' are same for all the buttons
body: <p>I have three buttons in my page out of which I need to click two buttons at different points of time. But I'm not able to do this since the xpath and other html elements (<code>id</code>, <code>class</code>, <code>type</code>, <code>value</code> and <code>name</code>) are same for all these buttons. How can I uniquely identify these buttons for clicking? Note that the buttons are at different location in the same page, and they need to be clicked one after the other.</p>
  
  <p>I have tried like this:</p>
  
  <pre><code>driver.findElement(By.xpath("(//input[@name='submit'])[2]")).click(); 
  </code></pre>
  
  <p>and was able to click one button. But when I tried with '3' instead of two, nothing happened.
  HTML:</p>
  
  <pre><code>&lt;document&gt;
  &lt;html class="js" lang="en" dir="ltr" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;body class="not-front logged-in page-manage-listing-agent no-sidebars tableHeader-processed"&gt;
  &lt;!-- wrapper --&gt;
  &lt;div id="wrapper"&gt;
  &lt;!-- container --&gt;
  &lt;div id="container"&gt;
  &lt;!-- page_wrapper --&gt;
  &lt;div id="page_wrapper"&gt;
  &lt;!-- page --&gt;
  &lt;div id="page"&gt;
  &lt;!-- page-header --&gt;
  &lt;div id="page-header" class="style_float"&gt;
  &lt;!--end page-header --&gt;
  &lt;div class="clear"/&gt;
  &lt;!-- main menu --&gt;
  &lt;div class="style_main_menu"&gt;
  &lt;!--end main menu --&gt;
  &lt;div class="clear"/&gt;
  &lt;div id="subheading" class="style_flow"&gt;
  &lt;div class="clear"/&gt;
  &lt;!-- center --&gt;
  &lt;div id="center" class="style_center_content_default"&gt;
  &lt;!-- content above --&gt;
  &lt;div class="style_content_above_wrapper"&gt;
  &lt;!-- end content above --&gt;
  &lt;!-- left side bar --&gt;
  &lt;div id="sidebar-left" class="sidebar"&gt;
  &lt;!--end left side bar --&gt;
  &lt;div class="style_content_main_wrapper"&gt;
  &lt;div id="content-main"&gt;
  &lt;!-- error message --&gt;
  &lt;div class="error-message "/&gt;
  &lt;!-- content help --&gt;
  &lt;div class="content-help"/&gt;
  &lt;div class="clear-block"&gt;
  &lt;h3 class="style_sub_title"/&gt;
  &lt;form id="rmls-manage-agent-listing" method="post" accept-charset="UTF-8" action="/manage-listing-agent/4740/7/Next"&gt;
  &lt;div&gt;
  &lt;h3 class="style_sub_title"&gt;Tour Activity Status&lt;/h3&gt;
  &lt;input id="edit-step" type="hidden" value="8" name="step"/&gt;
  &lt;div class="container-inline-date form-item date-clear-block"&gt;
  &lt;div class="container-inline-date form-item date-clear-block"&gt;
  &lt;div class="form-submit-button"&gt;
  &lt;input id="form-k4S3uBJXVTcXq3Ix1Shkjt3nf-62zmYfOpkAslvJ8tQ" type="hidden" value="form-k4S3uBJXVTcXq3Ix1Shkjt3nf-62zmYfOpkAslvJ8tQ" name="form_build_id"/&gt;
  &lt;input id="edit-rmls-manage-agent-listing-form-token" type="hidden" value="f18fc36d4d750ae3912d9cc941aa5c72" name="form_token"/&gt;
  &lt;input id="edit-rmls-manage-agent-listing" type="hidden" value="rmls_manage_agent_listing" name="form_id"/&gt;
  &lt;table class="sticky-header" style="position: fixed; top: 0px; width: 605px; left: 480px; visibility: hidden;"&gt;
  &lt;table class="statistic_table sticky-enabled sticky-table"&gt;
  &lt;div id="style_activity_text" class="style_sub_title_two"&gt;Premium Placements&lt;/div&gt;
  &lt;div id=""&gt;
  &lt;form id="rmls-activity-report-placement-list-form" method="post" accept-charset="UTF-8" action="/manage-listing-agent/4740/7/Next"&gt;
  &lt;div&gt;
  &lt;div class="placement_save"&gt;
  &lt;input id="submit" class="form-submit bluebutton" type="submit" value="Save" name="submit"/&gt;
  &lt;/div&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_div"&gt;
  &lt;div class="placement_submit_div"&gt;
  &lt;input id="submit" class="form-submit bluebutton" type="submit" value="Save" name="submit"/&gt;
  &lt;/div&gt;
  &lt;input id="form-8AJLqZQrgw0cybk8XOkWelCk6iaSJK_7G21QiBLdNKg" type="hidden" value="form-8AJLqZQrgw0cybk8XOkWelCk6iaSJK_7G21QiBLdNKg" name="form_build_id"/&gt;
  &lt;input id="edit-rmls-activity-report-placement-list-form-form-token" type="hidden" value="4305d09bc8205b6d0db44711023395c9" name="form_token"/&gt;
  &lt;input id="edit-rmls-activity-report-placement-list-form" type="hidden" value="rmls_activity_report_placement_list_form" name="form_id"/&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;div class="style_sub_title_two"&gt;Custom Placements&lt;/div&gt;
  &lt;a class="custom-placement-link" href="/%2523"&gt;Add New&lt;/a&gt;
  &lt;div id="activity_report_placement_form_div" style="display:none;"&gt;
  &lt;form id="rmls-activity-report-placement-form" enctype="multipart/form-data" method="post" accept-charset="UTF-8" action="/manage-listing-agent/4740/7/Next"&gt;
  &lt;div&gt;
  &lt;div id="placement_title-wrapper" class="form-item"&gt;
  &lt;div id="placement_link-wrapper" class="form-item"&gt;
  &lt;div id="edit-thumb-wrapper" class="form-item"&gt;
  &lt;input id="edit-placement-listing-id" type="hidden" value="4740" name="placement_listing_id"/&gt;
  &lt;input id="submit" class="form-submit bluebutton" type="submit" value="Save" name="submit"/&gt;
  &lt;input id="form-edEgxWrM-VMdRs75vREPtHbONXyCmJR4KkZRkRoSU2Y" type="hidden" value="form-edEgxWrM-VMdRs75vREPtHbONXyCmJR4KkZRkRoSU2Y" name="form_build_id"/&gt;
  &lt;input id="edit-rmls-activity-report-placement-form-form-token" type="hidden" value="185635f8c3122f16a07b5b626e7fc473" name="form_token"/&gt;
  &lt;input id="edit-rmls-activity-report-placement-form" type="hidden" value="rmls_activity_report_placement_form" name="form_id"/&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;div id=""&gt;
  &lt;form id="rmls-activity-report-custom-placement-list-form" method="post" accept-charset="UTF-8" action="/manage-listing-agent/4740/7/Next"&gt;
  &lt;div class="style_sub_title_two"&gt;Activity Report Email Recipients&lt;/div&gt;
  &lt;div class="style_mail_warpper"/&gt;
  &lt;div id=""&gt;
  &lt;form id="rmls-activity-report-receipient-form" method="post" accept-charset="UTF-8" action="/manage-listing-agent/4740/7/Next"&gt;
  &lt;div&gt;
  &lt;div id="receipient_add-wrapper" class="form-item"&gt;
  &lt;input id="activity_listing_id" type="hidden" value="4740" name="activity_listing_id"/&gt;
  &lt;div class="rmls_activity_report_receipient_overview_div"&gt;
  &lt;div class="receipient_submit_div"&gt;
  &lt;input id="send-submit" class="form-submit style_activity_recipient_sent bluebutton" type="submit" value="Send Report Now" name="op"/&gt;
  &lt;input id="submit" class="form-submit style_activity_recipient bluebutton" type="submit" value="Save" name="op"/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;div class="activity_report"&gt;Top 10 Referrers:&lt;/div&gt;
  &lt;table class="referrer_table"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;div id="dialog-manage-listing"/&gt;
  &lt;/div&gt;
  &lt;!-- content main --&gt;
  &lt;!-- right side bar --&gt;
  &lt;!-- end right side bar --&gt;
  &lt;/div&gt;
  &lt;!-- style_content_main_wrapper --&gt;
  &lt;/div&gt;
  &lt;!-- center --&gt;
  &lt;div class="clear"/&gt;
  &lt;div id="footer"&gt;
  &lt;/div&gt;
  &lt;!--end page --&gt;
  &lt;/div&gt;
  &lt;!--end page_wrapper --&gt;
  &lt;div id="dialog"/&gt;
  &lt;script type="text/javascript"&gt; &lt;!--//--&gt;&lt;![CDATA[//&gt;&lt;!-- var _gaq = _gaq || [];_gaq.push(["_setAccount", "UA-37131766-1"]);_gaq.push(["_trackPageview"]);(function() {var ga = document.createElement("script");ga.type = "text/javascript";ga.async = true;ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(ga, s);})(); //--&gt;&lt;!]]&gt; &lt;/script&gt;
  &lt;script type="text/javascript"&gt; &lt;!--//--&gt;&lt;![CDATA[//&gt;&lt;!-- jQuery.extend(Drupal.settings, { "CToolsAJAX": { "scripts": { "/sites/all/modules/jquery_update/replace/jquery.min.js": true, "/misc/drupal.js": true, "/sites/all/modules/blockui/jquery.blockUI.js": true, "/sites/all/modules/blockui/blockui.js": true, "/sites/all/modules/block_edit/block_edit.js": true, "/sites/all/modules/google_analytics/googleanalytics.js": true, "/sites/all/modules/nice_menus/superfish/js/superfish.js": true, "/sites/all/modules/nice_menus/superfish/js/jquery.bgiframe.min.js": true, "/sites/all/modules/nice_menus/superfish/js/jquery.hoverIntent.minified.js": true, "/sites/all/modules/nice_menus/nice_menus.js": true, "/sites/all/modules/jquery_ui/jquery.ui/ui/minified/ui.core.min.js": true, "/sites/all/modules/jquery_ui/jquery.ui/ui/minified/ui.dialog.min.js": true, "/sites/all/modules/jquery_ui/jquery.ui/ui/minified/ui.draggable.min.js": true, "/sites/all/modules/jquery_ui/jquery.ui/ui/minified/ui.droppable.min.js": true, "/sites/all/modules/jquery_ui/jquery.ui/ui/minified/ui.sortable.min.js": true, "/sites/all/modules/rmls/js/rmls.js": true, "/sites/all/modules/rmls/jquery.confirm/jquery.confirm.js": true, "/sites/all/modules/rmls/clippy/jquery.clippy.js": true, "/sites/all/modules/jquery_ui/jquery.ui/ui/minified/ui.datepicker.min.js": true, "/sites/all/modules/date/date_popup/lib/jquery.timeentry.pack.js": true, "/sites/all/modules/date/date_popup/date_popup.js": true, "/misc/tableheader.js": true, "/sites/all/modules/jquery_update/replace/jquery.form.js": true, "/sites/all/modules/ctools/js/ajax-responder.js": true, "/sites/all/modules/jquery_ui/jquery.ui/ui/minified/ui.resizable.min.js": true, "/sites/all/modules/dialog/dialog.js": true, "/sites/all/modules/rmls_order_verification/custom.js": true, "/sites/all/modules/rmls_order_verification/modal-window.min.js": true }, "css": { "/modules/node/node.css": true, "/modules/system/defaults.css": true, "/modules/system/system.css": true, "/modules/system/system-menus.css": true, "/modules/user/user.css": true, "/sites/all/modules/block_edit/block_edit.css": true, "/sites/all/modules/cck/theme/content-module.css": true, "/sites/all/modules/ckeditor/ckeditor.css": true, "/sites/all/modules/ctools/css/ctools.css": true, "/sites/all/modules/date/date.css": true, "/sites/all/modules/date/date_popup/themes/datepicker.css": true, "/sites/all/modules/date/date_popup/themes/jquery.timeentry.css": true, "/sites/all/modules/filefield/filefield.css": true, "/sites/all/modules/nice_menus/nice_menus.css": true, "/sites/all/modules/nice_menus/nice_menus_default.css": true, "/sites/all/modules/rmls/jquery.confirm/jquery.confirm.css": true, "/sites/all/modules/jquery_ui/jquery.ui/themes/default/ui.all.css": true, "/sites/all/modules/jquery_ui/jquery.ui/themes/default/ui.datepicker.css": true, "/sites/all/modules/ubercart/uc_attribute/uc_attribute.css": true, "/sites/all/modules/ubercart/uc_order/uc_order.css": true, "/sites/all/modules/ubercart/uc_product/uc_product.css": true, "/sites/all/modules/ubercart/uc_store/uc_store.css": true, "/sites/all/modules/cck/modules/fieldgroup/fieldgroup.css": true, "/sites/all/modules/views/css/views.css": true, "/sites/all/themes/rmls_webtheme/rmls.css": true, "/sites/all/themes/rmls_webtheme/style.css": true, "/sites/all/themes/rmls_webtheme/grid.css": true, "/sites/all/themes/rmls_webtheme/order_verification.css": true, "/sites/all/modules/rmls_order_verification/modal-window.css": true } } }); //--&gt;&lt;!]]&gt; &lt;/script&gt;
  &lt;/div&gt;
  &lt;!--end container --&gt;
  &lt;/div&gt;
  &lt;!--end wrapper --&gt;
  &lt;script type="text/javascript"&gt;window.NREUM||(NREUM={});NREUM.info={"beacon":"bam.nr-data.net","licenseKey":"61afc6e03f","applicationID":"10285903","transactionName":"ZwQAMUZYW0QAAkZaDF5OIwZAUFpZThNfXxBvDAMLVV5QaAAGV10Xbw0LFkBQW1A+B11BDm8WEARESVBF","queueTime":0,"applicationTime":8543,"atts":"S0MDRw5CSEo=","errorBeacon":"bam.nr-data.net","agent":""}&lt;/script&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;/document&gt;
  </code></pre>