How can I find this element and click on link ? This is a hover button with aim to export data.
<a title="Excel" alt="Excel" onclick="$find('ReportViewerControl').exportReport('EXCELOPENXML');" href="javascript:void(0)">Excel</a>
I tried :
driver.find_element(By.XPATH, "//a[@title='Excel']").click()
driver.find_element(By.CSS_SELECTOR, "a.ActiveLink[@title='Excel']").click()
But none of them are working. Thanks for your help.
CodePudding user response:
I have no idea why not worked what you tried, you did not share your Selenium code.
As per shared here element HTML - based on onclick
attribute try clicking it by one of the following:
driver.find_element(By.XPATH, "//a[@title='Excel'][contains(@onclick,'ReportViewerControl')]").click()
or
driver.find_element(By.XPATH, "//a[@title='Excel'][contains(@onclick,'EXCELOPENXML')]").click()
More locators can be created, but again, click may not work since the locator is not unique or maybe the element is hidden or overlapped or out of the visible view port or still not loaded... We can't know based on what you shared in ypur question so far.
Also, locators defined by XPath can be done with CSS Selectors and vice versa (in most cases).
CodePudding user response:
Without knowing the actual URL and site, it will be difficult to pinpoint the issue, but another common alternative would be executing the script directly using execute_script
function, something like this
driver.execute_script('$find('ReportViewerControl').exportReport('EXCELOPENXML');')