2

I am using selenium webdriver with python to navigate through a site and I can not figure out how to select this button.

<button onclick="addAutoTrade();blur();" type="button" style="background-
color:#c7c7c7;">Add</button>

The button is surrounded by a class but within the class are 2 buttons. I have tried using

driver.find_element_by_link_text("Add")
driver.find_element_by_partial_link_text("Add")
driver.find_element_by_name("Add")

There is no obvious id so I am stuck and I apologize if this is trivial. How can I click this button?

Nick Pavini
  • 312
  • 3
  • 15

1 Answers1

2

try this, hope this works for you:

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

buttonXpath = "//button[contains(.,'Add')]"

element = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,buttonXpath)))
element.click()

You can learn more about waits here and check selenium expected_conditions. these are quite usefull.
You can also see these topics about selecting buttons by text, they might help:

topic 1
topic 2

Rayhane Mama
  • 2,374
  • 11
  • 20