I would like to gather an element with the class name crash_crashGameCoefficient__M8rxs
using selenium. My current code is listed below and just returns and empty list when it should be returning the item with the class name crash_crashGameCoefficient__M8rxs
. Please help!
import matplotlib.pyplot as plt, json, colorama
colorama.init(autoreset=True)
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
x = []
y = []
chromedriver = 'chromedriver.exe'
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=d)
URL = 'https://bloxflip.com/crash'
driver.get(URL)
thing = driver.find_elements_by_class_name('crash_crashGameCoefficient__M8rxs')
print(thing)
CodePudding user response:
One thing that could cause the issue is the page getting loaded too slowly before the driver.find_elements_by_class_name
looks for the element. Test by adding an implicit wait driver.implicitly_wait(10)
, this could be changed to a more suitable fluent wait if necessary.
CodePudding user response:
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(driver, 30)
URL = 'https://bloxflip.com/crash'
driver.get(URL)
thing = wait.until(EC.presence_of_element_located((By.XPATH,"//*[contains(@class,'crash_crashGameCoefficient__')]")))
print(thing)
Should be a simple wait for the element to be present.