title: Selecting a variable property in Selenium with Python
body: <p>I did a code to search number by number and do something if the number is what i want, the code works, but i trying to select this number with a better way:</p>
  <pre><code># -*- encoding: utf-8 -*-
  
  from selenium import webdriver
  from selenium.webdriver.common.action_chains import ActionChains
  from selenium.webdriver.support.wait import WebDriverWait
  
  # Chromedriver and url
  driver = webdriver.Chrome(executable_path=r&quot;C:\Users\Gabri\anaconda3\chromedriver.exe&quot;)
  wait: WebDriverWait = WebDriverWait(driver, 20)
  driver.get('https://osu.ppy.sh/beatmapsets/941078')
  
  # The list of all numbers
  maps = driver.find_elements_by_css_selector(&quot;&quot;&quot;.beatmapset-beatmap-picker__beatmap&quot;&quot;&quot;)
  
  # Loop for clean the string and convert to float
  for stars in maps:
      actions = ActionChains(driver)
      actions.move_to_element(stars).perform()
  
      # I found this way to clean and show, is a lot of steps ... but it works =/
      treatment = driver.find_element_by_css_selector('.beatmapset-header__star-difficulty').text
      treatment = treatment .replace('Star Difficulty ', '')
      treatment = treatment .replace(',', '.')
      clean = float(treatment )
  
      # This way this is much more efficient, but I can't make it work
      attempt = driver.find_element_by_css_selector(&quot;&quot;&quot;.beatmap-icon&quot;&quot;&quot;).get_property('data-stars')
  
      # In final, both numbers have to be the same (at least that's how it was supposed to happen)
      print(f'{attempt=}\n{clean=}\n')
  
  </code></pre>
  <p>I already tried <code>attempt = driver.find_elements_by_css_selector(&quot;&quot;&quot;.beatmap-icon&quot;&quot;&quot;)[maps.index(stars)].get_property('data-stars')</code> but returns <code>None</code></p>
  <p>The numbers that i trying to select is these:
  <a href="https://i.stack.imgur.com/zF74s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zF74s.png" alt="enter image description here" /></a></p>
  <p>Basically, the idea is show each number that appear below:</p>
  <p><a href="https://i.stack.imgur.com/3VqiZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3VqiZ.png" alt="difficulty number" /></a></p>
  <p>But using just the <code>attempt</code> variable or something short like this</p>
  <p>Someone can help me with this selector?</p>
  <h1>FINAL CODE:</h1>
  <pre><code># -*- encoding: utf-8 -*-
  
  from selenium import webdriver
  from selenium.webdriver.common.action_chains import ActionChains
  from selenium.webdriver.support.wait import WebDriverWait
  
  driver = webdriver.Chrome(executable_path=r&quot;C:\Users\Gabri\anaconda3\chromedriver.exe&quot;)
  wait: WebDriverWait = WebDriverWait(driver, 20)
  driver.get('https://osu.ppy.sh/beatmapsets/941078')
  maps = driver.find_elements_by_css_selector(&quot;&quot;&quot;.beatmapset-beatmap-picker__beatmap&quot;&quot;&quot;)
  
  for stars in maps:
      actions = ActionChains(driver)
      actions.move_to_element(stars).perform()
  
      attempt2 = float(driver.find_element_by_xpath(f&quot;(//div[contains(@class,'beatmap-icon')])[{maps.index(stars)+1}]&quot;).get_attribute('data-stars'))
  
      print(f'{attempt2=}\n')
  </code></pre>