Reputation: 115
Edit: Changed to Lakers game as the other one started
I'm learning how to webscrape betting odds and I've been stuck on this problem all day. When I load this website Betway, it goes to the 'Main Markets'(see image below). I would like to go to other tabs, e.g. 'Game Props' or '1st Half'.
url = "https://sports.betway.com/en/sports/evt/6183976"
driver = webdriver.Safari()
driver.get(url)
element = driver.find_element_by_xpath("/html/body/div/div/div[3]/div/div[1]/div/div[2]/div[4]/div/div[3]/div/div[2]/div/div[1]/div[2]/div/div/div[2]/div/div/div[4]/div/div")
element.click()
On other websites I've been able to use the find by elements function, followed by the click() function to navigate through pages. I can't get them to work on this site. The bottom image I included is the code from the website when I inspect it. I would really appreciate some advice here!
Upvotes: 1
Views: 139
Reputation: 193188
To click()
on the tab with text as Game Props you have to induce WebDriverWait for the element_to_be_clickable()
and you can use the following xpath based Locator Strategy:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(., 'login or register')]"))).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
Upvotes: 1