1

I am new to Selenium C# Nunit. I ran following line of codes

 IWebElement SplitCase = driver.FindElement(By.XPath(".//*[@id='OpportunityPageV2UsrSplitCase503e4272-cdbd-44d2-98c2-e67a2996c717ComboBoxEdit-el']"));
 SplitCase.Click();
        
 IWebElement SplitCaseYes = driver.FindElement(By.CssSelector("li[data-item-marker=Yes]"));

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0"));

 SplitCaseYes.Click();

I got following Message: Message: OpenQA.Selenium.ElementNotInteractableException : element not interactable (Session info: chrome=89.0.4389.114) Stack Trace: RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) RemoteWebElement.Execute(String commandToExecute, Dictionary2 parameters) RemoteWebElement.Click() TestClass1.CaseInfoTab() line 151

Then I add 10 seconds of wait :

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("li[data-item-marker=Yes]")));

I got this message:

Message:

OpenQA.Selenium.WebDriverTimeoutException : Timed out after 10 seconds

Stack Trace: DefaultWait1.ThrowTimeoutException(String exceptionMessage, Exception lastException) DefaultWait1.Until[TResult](Func`2 condition) TestClass1.CaseInfoTab() line 150

Please see attachment as well

Thank you for your help NG

enter image description here

enter image description here

Shikha
  • 23
  • 1
  • 7
  • Welcome to SO, could you clarify what you're trying to do and what is going wrong? Also what have you already tried to fix it? – Kevin Apr 08 '21 at 20:55
  • `.//*[@id='OpportunityPageV2UsrSplitCase503e4272-cdbd-44d2-98c2-e67a2996c717ComboBoxEdit-el'] `- this is the problem. Add his element html code – vitaliis Apr 08 '21 at 21:07
  • HI Vitallis ,I believe problem is with this code of line. SplitCaseYes.Click(); For this one I have been gettingthies message; ElementNotInteractableException : element not interactable. RemoteWebElement.Click() – Shikha Apr 09 '21 at 13:29
  • Can you please add as much data as possible to the question: link to site (if you are allowed), steps you execute and on which line of code you receive the error. Having this info will have to identify the problem more accurately. – vitaliis Apr 15 '21 at 15:11

3 Answers3

0

Your css selector seems to be wrong.Try now. It should be tagname[attributename='attributeval']

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("li[data-item-marker='Yes']")));

Or Use following xpath.

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//li[@data-item-marker='Yes' and text()='Yes']")));

Update:

Try with Java script executor.

IWebElement SplitCaseYes = driver.FindElement(By.CssSelector("li[data-item-marker='Yes']"));
IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", SplitCaseYes);
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • Hi KunduK I tried with your code of line, and got this message: Message: OpenQA.Selenium.WebDriverTimeoutException : Timed out after 10 seconds – Shikha Apr 09 '21 at 15:35
  • @user15574820 : it seems element is not visible on the page. try with JavaScript executor to click. try updated one and let me know. – KunduK Apr 09 '21 at 16:06
  • KunduK--- I did try with JavaScript but no luck . Got this message: Message: OpenQA.Selenium.ElementNotInteractableException : element not interactable (Session info: chrome=89.0.4389.114) Stack Trace: RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters) RemoteWebElement.Click() TestClass1.CaseInfoTab() line 156 – Shikha Apr 09 '21 at 17:14
0

Change

IWebElement SplitCase = driver.FindElement(By.XPath(".//*[@id='OpportunityPageV2UsrSplitCase503e4272-cdbd-44d2-98c2-e67a2996c717ComboBoxEdit-el']"));

to

IWebElement SplitCase = driver.FindElement(By.XPath("//div[contains(@id,'OpportunityPageV2UsrSplitCase')]"));

I am not sure if there is div In the beginning. I do not see it on the screenshot. Verify it. The locator that you use is not stable. Also add explicit waits.

Try 2:

For SplitCaseYes also try using this css selector: By.CssSelector('li[data-item-marker="Yes"]') or ul>li[data-item-marker=Yes] or their variations.

Also, add wait before clicking your element.

WebDriverWait wait = new WebDriverWait(PropertiesCollection.driver, TimeSpan.FromSeconds(30));
WebElement el = wait.until(ExpectedConditions.ElementToBeClickable(By.CssSelector("your selector")));
el.click();

Possible Ajax problem

There is a probability that your element is not interactable because of Ajax requests:

Try this before clicking as well:

public void WaitForAjax()
{
    var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
    wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0"));
}

Update 4. There is a probability that locator above is not unique (did you check CSS locators I proposed?) Try the following xpath:

//div[contains(@data-item-marker,'Split Case')]/ul/li[@data-item-marker='Yes']

This locator first looks at data-item-marker with Split Case text, then goes level down to ul, and finally to the second li element. In this case instead of /li[@data-item-marker='Yes'] it's possible to use just li[2]

Before executing any code with locators, you should check if it's unique.

enter image description here

Update 5: I found out that C#'s Selenium ExpectedConditions is obsolete: C# Selenium 'ExpectedConditions is obsolete' Try using: SeleniumExtras.WaitHelpers.ExpectedConditions. You'll need to import it with Nuget package manager. Here is the example:

var wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(10000));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.CssSelector("ul>li[data-item-marker=Yes]")));
vitaliis
  • 4,082
  • 5
  • 18
  • 40
  • Hi Vitallis ,I believe problem is with this code of line. SplitCaseYes.Click(); For this one I have been getting this message; ElementNotInteractableException : element not interactable. RemoteWebElement.Click() – – Shikha Apr 09 '21 at 15:37
  • What is the result? – vitaliis Apr 09 '21 at 20:20
  • Vitallis-- as suggested I did try with this code: IWebElement SplitCaseYes = driver.FindElement( By.CssSelector("ul>li[data-item-marker='Yes']")); IJavaScriptExecutor executor = (IJavaScriptExecutor)driver; executor.ExecuteScript("arguments[0].click();", SplitCaseYes); SplitCaseYes.Click(); I got OpenQA.Selenium.ElementNotInteractableException : element not interactable – Shikha Apr 09 '21 at 20:27
  • Message: OpenQA.Selenium.ElementNotInteractableException : element not interactable (Session info: chrome=89.0.4389.114) Stack Trace: RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters) RemoteWebElement.Click() – Shikha Apr 09 '21 at 20:28
  • OK. I'll update the answer with more suggestions – vitaliis Apr 09 '21 at 20:43
  • 1
    Thank you so much for your support – Shikha Apr 09 '21 at 20:51
  • Hi Vitallis, I will update you about result soon. Actually our environment is down since Saturday, our team is working on it. – Shikha Apr 12 '21 at 13:02
  • Hi Vitaliis I did try and got this message: Message: OpenQA.Selenium.ElementNotInteractableException : element not interactable (Session info: chrome=89.0.4389.114) Stack Trace: RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters) RemoteWebElement.Click() TestClass1.CaseInfoTab() line 163 – Shikha Apr 12 '21 at 19:07
  • I did use following code of lines: IWebElement SplitCaseYes = driver.FindElement( By.CssSelector("ul>li[data-item-marker='Yes']")); IJavaScriptExecutor executor = (IJavaScriptExecutor)driver; executor.ExecuteScript("arguments[0].click();", SplitCaseYes); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0")); SplitCaseYes.Click(); – Shikha Apr 12 '21 at 19:08
  • @vitallis do you have any other suggestion or remark ? – Shikha Apr 13 '21 at 17:14
  • I'll try to check it later today? What is the status? Looks like a long issue – vitaliis Apr 13 '21 at 17:17
  • You can try this https://stackoverflow.com/questions/64558779/cannot-click-on-toggle-with-selenium-because-of-elementnotinteractableexception this is for Python but is applicable to any language and always workds for me. I don't know why someone downvoted it yesterday. You can update it) – vitaliis Apr 13 '21 at 17:19
  • Thanks Vitaliis, I will try this piece of codes and let you know the results. – Shikha Apr 15 '21 at 12:57
  • FYI I have voted to your answer:) As you always try to help others. May God bless you. – Shikha Apr 15 '21 at 14:17
  • You are welcome. Which answer? I'll try to check your problem today again. – vitaliis Apr 15 '21 at 14:29
  • If you want to upvote an answer, you should click ^ (up) arrow, not down :) – vitaliis Apr 15 '21 at 15:31
  • I did clicks on up arrow, I believe. Anyways I clicks on up arrow again :) – Shikha Apr 15 '21 at 15:59
  • Thanks! Can you please add more details to the question if it's possible? – vitaliis Apr 15 '21 at 16:00
  • I'll return to your question later today. – vitaliis Apr 15 '21 at 16:01
  • I have added one more image, let me know what other info I can provide you. – Shikha Apr 15 '21 at 16:13
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/231179/discussion-between-vitaliis-and-shikha). – vitaliis Apr 15 '21 at 16:36
0

As for the problem I had, the issue was that there were two elements on the page with the same ID, the first of which was not clickable. So after calling the click method, the error "element not interactable" would occur.

Solution :

After changing the ID of the elements, my problem was solved.

More explanation :

With the following html fragment, the command driver.FindElement(By.Id("btn1")).Click(); An error is encountered :

<button type="button" id="btn1" style="display:none">first button with id "btn1"</button>
<button type="button" id="btn1" >second button with id "btn1"</button>

But there will be no problem in the following html fragment :

<button type="button" id="btn0" style="display:none">button with id "btn0"</button>
<button type="button" id="btn1" >button with id "btn1"</button>