How to take the balance value from a tag using Selenium?

Viewed 30

I'm trying to take the balance value from its tags HTML code of the balance: I tried different ways.All paths are like through CLASS_NAME, XPATH,CSS_SELECTORS, but none of them helps.I don't know what I'm doing wrong? Maybe I'm not finding the way to the right tag correctly? Who is not difficult, can explain the HTML code below how to get a balance? Who will help to deduce the value of the balance I will be very grateful

HTML-code

My function:

def bet():
driver.get(url = "https://stake.jp/casino/games/evolution-stake-exclusive-speed-baccarat-1")
time.sleep(2)
driver.find_element(By.XPATH, "/html/body/div[1]/div[2]/div[2]/div[4]/div/div/div/div[1]/div/div/div[2]/div/div/div[1]/div/div/div/div/div/div[1]/div/div[2]/button").click()
time.sleep(2)
# driver.find_element(By.CLASS_NAME/XPATH/CSS_SELECTOR, "css selector") #one of them
# #OR
# WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CLASS_NAME, "class name here")))

Error with driver.find_element() method:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".balance"}

Error with EC.presence_of_element_located() method:

    WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH, 
"/html/body/div[4]/div/div[2]/div/div/div[7]/div[3]/div/div/div[1]")))

  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\support\wait.py", line 90, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
1 Answers

This is one way of getting that information (it comes as undefined to me, probably because I'm not logged in):

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument('disable-notifications')

chrome_options.add_argument("window-size=1280,720")

webdriver_service = Service("chromedriver/chromedriver") ## path to where you saved chromedriver binary
browser = webdriver.Chrome(service=webdriver_service, options=chrome_options)
wait = WebDriverWait(browser, 20)
url = "https://stake.jp/casino/games/evolution-stake-exclusive-speed-baccarat-1"
browser.get(url)
try:
    WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[data-test="accept-cookie-consent"]'))).click()
except Exception as e:
    print('no cookie button!')
# t.sleep(5)
balance = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, "//*[@id='game']//following-sibling::div/span")))

print(balance.text)

Selenium docs can be found at https://www.selenium.dev/documentation/

Related