title: Selenium - not able to click button using Python
body: <p>I'm running into an issue trying to click on a specific button on my web application using Selenium with Python. The button shows up on a dialog that becomes available once another button is pressed.</p>
  
  <p>For example, my form has the following section:</p>
  
  <p><a href="https://i.stack.imgur.com/sN9Ws.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sN9Ws.png" alt="enter image description here"></a></p>
  
  <p>Once the 'Save Answers' button is pressed, an OK button shows up in a dialog above it.</p>
  
  <p><a href="https://i.stack.imgur.com/7nu5r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7nu5r.png" alt="enter image description here"></a></p>
  
  <p>I'm trying to click on this OK button, but it is not working as of right now.
  When I inspect this element on Chrome, I get the following items:</p>
  
  <pre><code>&lt;div class="bootbox modal fade my-modal in" tabindex="-1" role="dialog" style="display: block;"&gt;
  &lt;div class="modal-dialog"&gt;
  &lt;div class="modal-content"&gt;
  &lt;div class="modal-body"&gt;
  &lt;div class="bootbox-body"&gt;Your answers have been saved.&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
  &lt;button data-bb-handler="cancel" type="button" class="btn btn btn-primary"&gt;OK&lt;/button&gt;
  &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
  </code></pre>
  
  <p>With <code>&lt;button data-bb-handler="cancel" type="button" class="btn btn btn-primary"&gt;OK&lt;/button&gt;</code> being the button I am trying to click.</p>
  
  <p>I am using the following Python code to try this:</p>
  
  <pre><code>driver.find_element_by_id("saveQuestionsSection").click() #click Save Answer
  driver.find_element_by_xpath("//button[@type='button']").click() #click OK
  </code></pre>
  
  <p>But it is not working. I have tried to replicate this step using Selenium IDE and it works there, with the command looking like this:</p>
  
  <p>Command: <strong>click</strong></p>
  
  <p>Target: <code>xpath=(//button[@type='button'])[26]</code></p>
  
  <p>But I am not sure how to translate this into Python code.</p>
  
  <p>Any ideas?</p>