title: How to increase the speed of find_elements_by_xpath
body: <p>I am working on a selenium project. In the project I am opening multiple walmart pages and checking if there is a <code>nav</code> inside a div. If the <code>nav</code> exists do something else continue to the next page.</p>
  <p><a href="https://i.stack.imgur.com/eecNx.png?s=512" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eecNx.png?s=512" alt="enter image description here" /></a></p>
  <p>Right now The program is able to locate the nav if the nav exists in the page. but if the nav does not exist, it program takes too long to continue along with the code.</p>
  <p>Is there anyway to increase the speed with which the program searches the code.</p>
  <p>this is my code</p>
  <pre><code>nav_button_path = &quot;//div[@class='modal modal--active-fill responsive-modal prod-fulfillmentOptionsModal prod-AccessFulfillmentModal prod-AccessSlidePanel']//nav[@class='persistent-subnav']&quot;
  nav_button = driver.find_elements_by_xpath(nav_button_path)
  
  if not nav_button:
      ...
  
  else:
      ...
  </code></pre>
  <p>in the above code the <code>else condition</code> runs if the nav is found. This runs quickly. But the <code>if condition</code> takes a long time to run as the program takes a long time to search for the nav in the webpage if the nav does not exist.</p>
  <p>Thanks in advance</p>