1
votes

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

2
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
.//*[@id='OpportunityPageV2UsrSplitCase503e4272-cdbd-44d2-98c2-e67a2996c717ComboBoxEdit-el'] - this is the problem. Add his element html code - vitaliis
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
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

2 Answers

0
votes

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);
0
votes

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]")));