0

I am trying to download an excel file using Selenium Python using the below code:

download=driver.find_element_by_css_selector("span[data-reactid='.0.1.0.0.1.1.1.0.1.0.1'>Download Orders]")

The element of the download button look like: enter image description here

The piece of code above isnt working. Can someone help?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user2458552
  • 419
  • 2
  • 5
  • 17

3 Answers3

0

Your CSS locator is wrong. Please try to click with below xpath.

//span[.='Download Orders']
Muzzamil
  • 2,823
  • 2
  • 11
  • 23
0

The desired element is a React element so to locate and click() on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using XPATH with normalize-space():

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[normalize-space()='Download Orders']"))).click()
    
  • Using XPATHand contains():

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(., 'Download Orders')]"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

I agree with Muzzamil that the CSS locator you have used seems wrong. @ is needed to select the attribute data-reactid. You can try XPath:

//span[@data-reactid='.0.1.0.0.1.1.1.0.1.0.1'] 

If you want to include also the text, try:

//span[@data-reactid='.0.1.0.0.1.1.1.0.1.0.1'][contains(text(),'Download Orders')]
K. B.
  • 3,342
  • 3
  • 19
  • 32