I want to automate download to local and sent report (dashboard data studio) via email, but when I run the code in data studio , the chrome driver open, show notice "Report cannot be viewed at this time or does not have access" what should I do ? here is my code:
# login to datastudio & refresh the newest data
self.chrome_driver.get(self.url)
self.chrome_driver.find_element_by_id("identifierId").send_keys(self.email + u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys(self.password+u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.XPATH, self.report_refresh))).click() # refresh report data
time.sleep(15)
# download file to local path
try:
ActionChains(self.chrome_driver).context_click(self.chrome_driver.find_element_by_xpath(self.product_export)).perform()
self.quick_wait.until(EC.element_to_be_clickable((By.XPATH, self.product_download))).click()
time.sleep(20)
self.quick_wait.until(EC.element_to_be_clickable((By.ID, self.report_download))).click()
self.chrome_driver.find_element_by_css_selector(self.report_to_pdf).click()
time.sleep(20)
except AssertionError as error:
print(error)
self.chrome_driver.quit()
i got error msg like:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="identifierId"]"}
Might be an issue with page load.try adding implicit or explicit wait.
1.Apply required wait (implicit or explicit wait)
Implicit wait
driver.implicitly_wait(15)
Explicit wait:
wait = WebDriverWait(driver, 10)
wait.until(ec.visibility_of_element_located((By.XPATH, "//*[contains(@class,'result-list-entry')]")))
Example:
self.chrome_driver.implicitly_wait(15)
self.chrome_driver.get(self.url)
self.quick_wait.until(EC.element_to_be_clickable((By.ID, "identifierId")))
self.chrome_driver.find_element_by_id("identifierId").send_keys(self.email + u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys(self.password+u'\ue007')
2.Check whether element is a child of iframe element. if so, switch to iframe and try to click
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.