I Can't get element inside an app in a webpage with selenium, python (WebScrapping)

Question:

No matter what i try to find inside the aviator game in
https://estrelabet.com/ptb/games/detail/casino/demo/7787
it always returns

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

i’m trying to get everything inside the results
they are all children to div with class ‘payouts-block’

i can even login to the website and go into the game, but i can’t get any element from inside it

# navegador.find_element(By.CLASS_NAME,'payouts-block').text
# navegador.find_element(By.XPATH,'/html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[1]/app-stats-widget/div/div[1]/div')
# /html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[1]/app-stats-widget/div/div[1]/div
# navegador.find_element(By.CLASS_NAME,'amount font-family-number')
# WebDriverWait(navegador,15).until(EC.element_to_be_clickable('number font-family-number'))

these are all the functions i tried so far, always with the same error

Asked By: Teteeu14

||

Answers:

Problem is that the elements you are looking for are inside an iframe, so you need to switch to iframe in order to use them.

Code working:

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

# Initiate the ddriver and navigate
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://estrelabet.com/ptb/games/detail/casino/demo/7787')

# We save the iframe where the elements you want to get are located
iframe = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "iframeDefaultSize")))

# We switch to that iframe
driver.switch_to.frame(iframe)

# Once we switched to the iframe, we can get the elements you wanted
blocks = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, "(//div[@class='payouts-block'])[1]//app-payout-item/div")))

# For every element you show the text
for block in blocks:
    print(block.get_attribute('textContent'))

If after using the iframe you want use other elements out of the iframe you need to get back to the main frame, you can do line:

driver.switch_to.default_content();
Answered By: Jaky Ruby