0

I am trying to create a python + selenium script in order to fetch CSV from a salesforce pardot page.

Can Somebody please help me in accessing the nested span element inside the dropdown list which will be generated on button click.

I am adding my code done so far and I am getting Timeout Error While running my script.

from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
try:
    chrome_options = webdriver.ChromeOptions()
    prefs = {'download.default_directory': r'C:\Pardot'}
    chrome_options.add_experimental_option('prefs', prefs)
    driver = webdriver.Chrome(executable_path="D:\XXX XXXX\XXXX\drivers\chromedriver.exe", options=chrome_options)
    driver.get('https://pi.pardot.com/engagementStudio/studio#/15627/reporting')
    user_name = driver.find_element_by_css_selector('#email_address')
    user_name.send_keys('XXXXXXXXXXXXXXXXXXX')
    password = driver.find_element_by_css_selector('#password')
    password.send_keys('XXXXXXXXXXXXXXXXX)
    submit_button = driver.find_element_by_css_selector('input.btn')
    submit_button.click()
    WebDriverWait(driver, 10).until(
    EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe#content-frame")))
    WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element_value(text_='All Time',locator=(By.CSS_SELECTOR,"span[data-qa='reporting-filter-trigger-value']")))

except (RuntimeError) as e:
    print(e)
finally:
    time.sleep(10)
    driver.close()

Screenshot for span DOM element


Error Stack trace:

C:\Users\Vipul.Garg\AppData\Local\Programs\Python\Python37\python.exe "D:/Vipul Garg Backup/XXXX/testingCSVfetching.py"
Traceback (most recent call last):
  File "D:/Vipul Garg Backup/XXXX/testingCSVfetching.py", line 22, in <module>
    WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element_value(text_='All Time',locator=(By.CSS_SELECTOR,"span[data-qa='reporting-filter-trigger-value']")))
  File "C:\Users\Vipul.Garg\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Vipul_Garg
  • 43
  • 1
  • 8

1 Answers1

0

try this approach

spans = driver.find_element_by_css_selector('.slds-button_reset.slds-grow.slds-has-blur-focus.trigger-button').get_attribute('innerHTML') print(spans) You should be getting all span.

  • Hi @benjie perez thanks for your response But I am getting error by using above. Error:-no such element: Unable to locate element: {"method":"css selector","selector":".slds-button_reset.slds-grow.slds-has-blur-focus.trigger-button"} – Vipul_Garg Mar 03 '20 at 08:39
  • is the element pre rendered via javascript? – Benjie Perez Mar 03 '20 at 08:41
  • yes it is Dynamic DOM element and under Iframe @benjie – Vipul_Garg Mar 03 '20 at 09:01
  • whats the output of `WebDriverWait(driver, 10).until( EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe#content-frame"))).get_attribute('innerHTML)` did the target button you want appeared? – Benjie Perez Mar 03 '20 at 10:33
  • @benzie getting error- EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe#content-frame"))).get_attribute('innerHTML') AttributeError: 'bool' object has no attribute 'get_attribute' – Vipul_Garg Mar 03 '20 at 10:53
  • @benzie Pls go through my question again once I have edited it to correct Title. – Vipul_Garg Mar 03 '20 at 10:59