0

I have html which looks as following:

<button onclick="newInputScenario()" class="btn btn-primary">New...</button>&nbsp;
  <button onclick="uploadInputScenario()" class="btn btn-primary">Upload...</button>&nbsp;
  <button onclick="diffScenarios('idb');" class="btn btn-primary">Diff...</button>&nbsp;&nbsp;
  <button onclick="newUserScenario()" class="btn btn-primary">New UDS...</button>

But all the above have same class name.

I have been using the following code but it won't work for above as I need to click the second button Upload...

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

if __name__ == '__main__':
    path_to_chromedriver = r'C:\chromedriver'  # change path as needed
    browser = webdriver.Chrome(executable_path=path_to_chromedriver)
    wait = WebDriverWait(browser, 5)
    wait.until(EC.presence_of_element_located((By.XPATH, "//button[@class='btn btn-primary']"))).click()

How do I modify my code above to be able to click Upload...

supputuri
  • 12,238
  • 2
  • 14
  • 34
Zanam
  • 3,540
  • 9
  • 42
  • 91

1 Answers1

1

Try with the below code.

wait.until(EC.presence_of_element_located((By.XPATH, "//button[@class='btn btn-primary'][.='Upload...']"))).click()

You can also use the below xpath.

//button[@class='btn btn-primary'][2]
//button[@onclick='uploadInputScenario()']
supputuri
  • 12,238
  • 2
  • 14
  • 34