Home > other >  How can I use selenium to click a button
How can I use selenium to click a button

Time:04-22

HTML snapshot of website:

The button is the rebounds button on 'https://app.prizepicks.com/board'. I've tried using the copy xPath feature, but that does not work.

CodePudding user response:

  1. Try to wait until the elements show up or use time.sleep()

  2. Below xpath works for me

    rebounds_btn = driver.find_element_by_xpath('//*[contains(text(), "Rebounds")]') rebounds_btn.click()

CodePudding user response:

Try the below,

   WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'Rebounds')]"))).click()

do not forget to import

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

CodePudding user response:

To click on the element with text as Rebounds you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following solution:

driver.get("https://app.prizepicks.com/board")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Rebounds']"))).click()

Note: You have to add the following imports :

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