1

I'm trying to click on a report inside an accordian element.

Ive tried various methods to identify the element but nothing i tried worked.

With XPath and Id I get the following error message:

OpenQA.Selenium.ElementNotInteractableException: 'element not interactable'

This is the code I've tried.

static IWebDriver driver = new ChromeDriver();
static IWebElement element;

driver.FindElement(By.XPath("//*[@id=\"ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0\"]")).Click();
driver.FindElement(By.Id("ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0")).Click();

This is the HTML inside the accordion that I'm targeting,

<a id="ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0" class="ReportImg" href="javascript:__doPostBack           ('ctl00$ContentPlaceHolder1$ReportCreator1$AccordionReportList_Pane_3_content$DataListReports$ctl00$LinkButtonReport','')">All Assessments</a>
KunduK
  • 32,888
  • 5
  • 17
  • 41
Lars7
  • 29
  • 7
  • Double-check your locator is unique... open the dev console and try `$$("#ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0")`. Does it return only one element? It seems like a crazy long locator to NOT be unique... but I've seen issues like this before where there were 2 or more elements on the page and the first wasn't visible, etc. – JeffC Apr 12 '21 at 14:23

1 Answers1

2

Element might not be visible while interacting try use WebDriverWait() and wait for ElementToBeClickable() and following locator.

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("ContentPlaceHolder1_ReportCreator1_DataListReports_3_LinkButtonReport_0"))).Click();

Or

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[text()='All Assessments']"))).Click();
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • Thanks Kunduk, both worked. I have a small issue though. "ExpectedConditions" has a squiggly line under it and the message said "deprecated". I can lable it Obsolete but I was hoping you might have a solution? – Lars7 Apr 12 '21 at 16:22
  • @Lars7 : Using NuGet, search for DotNetSeleniumExtras.WaitHelpers, and import that namespace into your class. check this answer https://stackoverflow.com/questions/49866334/c-sharp-selenium-expectedconditions-is-obsolete – KunduK Apr 12 '21 at 16:44
  • @Kundak Thanks again, you have been very helpful – Lars7 Apr 12 '21 at 17:02
  • @Lars7 : Glad to be able to help. – KunduK Apr 12 '21 at 17:06