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:
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:
Your CSS locator is wrong. Please try to click with below xpath.
//span[.='Download Orders']
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 XPATH
and 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
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')]