(Python) Selenium with ASP.NET report viewer: Click with explicit wait with WebDriverWait doesn't work

80 Views Asked by At

I am trying to extract a CSV report from our company's ASP.NET ReportViewer via selenium but it doesn't work with explicit wait.

My script fills out some textfields and clicks on a 'Generate report' button. Once the button has been clicked the report is shown and an additional toolbar appears where you can click on a menubutton (ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink) and select the file format to download the report.

Setup:

options = Options()
service = Service("chromedriver.exe")
driver = webdriver.Chrome(service=service, options=options)
driver.get("ASP.NET Report Website")

Working solution:

time.sleep(2)
menu = driver.find_element('xpath','//*[@id="ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink"]')
menu.click()
csv = driver.find_element('xpath',"//a[contains(@title, 'CSV')]")
driver.execute_script("arguments[0].click();", csv)

It did several tests to try to get the click done with explicit waits:

First approach with 'visibility_of_element_located'

WebDriverWait(driver, 10).until(EC.visibility_of_element_located(('xpath','//*[@id="ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink"]')))
menu = driver.find_element('xpath','//*[@id="ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink"]')
menu.click()

Result: Nothing happens but also no error

Second approach with 'presence_of_element_located'

WebDriverWait(driver, 10).until(EC.presence_of_element_located(('xpath','//*[@id="ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink"]')))
menu = driver.find_element('xpath','//*[@id="ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink"]')
menu.click()   

Result: Nothing happens but also no error

Third approach with 'presence_of_element_located'

WebDriverWait(driver, 10).until(EC.element_to_be_clickable(('xpath','//*[@id="ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink"]')))
menu = driver.find_element('xpath','//*[@id="ReportViewerControl_ctl05_ctl04_ctl00_ButtonLink"]')
menu.click()    

Result: Nothing happens but also no error

So waiting until the menu/button is shown is working and doesn't raise an error but I don't understand why the .click() doesn't work.

Edit 13.08
A working solution seems to be to wait until the VisibleReportContentReportViewerControl_ctl09 got any children. This dv contains the report.

/html/body/form[@id='ReportViewerForm']/span[@id='ReportViewerControl_ReportViewer']/div[@id='ReportViewerControl']/table[@id='ReportViewerControl_fixedTable']/tbody/tr[5]/td[3]/div[@id='ReportViewerControl_ctl09']/div[@id='VisibleReportContentReportViewerControl_ctl09']/*
WebDriverWait(driver, 10, poll_frequency=0.1).until(EC.visibility_of_element_located(('xpath',"/html/body/form[@id='ReportViewerForm']/span[@id='ReportViewerControl_ReportViewer']/div[@id='ReportViewerControl']/table[@id='ReportViewerControl_fixedTable']/tbody/tr[5]/td[3]/div[@id='ReportViewerControl_ctl09']/div[@id='VisibleReportContentReportViewerControl_ctl09']/*")))

But this is only a solution for the first report. I want to generate multiple reports and therefore I do not reload the page (it takes 4-5s to reload). The next childelement changes its id with every new report:

/html/body/form[@id='ReportViewerForm']/span[@id='ReportViewerControl_ReportViewer']/div[@id='ReportViewerControl']/table[@id='ReportViewerControl_fixedTable']/tbody/tr[5]/td[3]/div[@id='ReportViewerControl_ctl09']/div[@id='VisibleReportContentReportViewerControl_ctl09']/div[@id='Pecd2ee77db264acb9b0283d9b3fde149_1_oReportDiv']

Solution (probably not the best): I've implemented a logic that waits until there is a childelement for the first report then stores the id of the first child and waits in the next loop until the id has changed.

0

There are 0 best solutions below