I am using C# selenium web driver for some automation purpose in visual studio.When i run my code sometimes it is working perfectly,but sometimes it is throwing an error "Exception has been thrown by the target of an invocation".When i restart my system it is working fine,again it is showing error after multiple runs.It is happening while giving password after username.The webpage is like username,submit button,password,submit button to login in to website.Without giving password,it is clicking submit button again.
Code where exception occuring
if (ConfigurationManager.AppSettings["IsEncrypted"].ToLower() =="true")
{
UserName.SendKeys(ConfigurationManager.AppSettings["UserName"]);
Submit.Click();
Thread.Sleep(2000);
Password.SendKeys(Base64Decode(ConfigurationManager.AppSettings["Password"]));
Submit.Click();
}
This is the exception
Exception occured:Exception has been thrown by the target of an invocation.
Exception occured:Exception has been thrown by the target of an invocation.
Exception occured System.Reflection.TargetInvocationException: Exception has bee
n thrown by the target of an invocation. ---> OpenQA.Selenium.StaleElementRefere
nceException: stale element reference: element is not attached to the page docum
ent
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9e
ed),platform=Windows NT 6.1.7601 SP1 x86_64)
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response erro
rResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecu
te, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Click()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Objec
t[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
at OpenQA.Selenium.Support.PageObjects.WebDriverObjectProxy.InvokeMethod(IMet
hodCallMessage msg, Object representedValue)
at OpenQA.Selenium.Support.PageObjects.WebElementProxy.Invoke(IMessage msg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at OpenQA.Selenium.IWebElement.Click()
at JiraExtract.PageObjects.LoginPage.LoginToApplication() in C:/Program.cs:line 72
at JiraExtract.Automation.AutomationTest() in c:/Program.cs:line 80
at JiraExtractor.Program.Main(String[] args) in c:/Program.cs:line 14
Submit.Click();. Why do you need to click twice? Does the error occur at the 2nd submit?Passwordin your code a static class or a WebElement?Password.SendKeys("just testing");. Can the script click on the submit after enter this password?