我在Visual Studio中使用C#selenium web驱动程序来实现一些自动化目的。当我运行我的代码时,它有时会完美运行,但有时它会抛出一个错误“Exception has been displayed by the目标的调用“。当我重新启动我的系统时,它工作正常,再次显示错误多次运行后。它发生在给用户名后的密码。网页就像用户名,提交按钮,密码,提交按钮登录到网站。没有给密码,它再次点击提交按钮。陈旧的元素引用异常c#Selenium Webdriver
代码中的异常发生的历史
if (ConfigurationManager.AppSettings["IsEncrypted"].ToLower() =="true")
{
UserName.SendKeys(ConfigurationManager.AppSettings["UserName"]);
Submit.Click();
Thread.Sleep(2000);
Password.SendKeys(Base64Decode(ConfigurationManager.AppSettings["Password"]));
Submit.Click();
}
这是例外
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();'。为什么你需要点击两次?错误是否在第二次提交时发生? – Buaban
网站设计就像那样。首先我需要给用户名提交它,然后我应该给密码并再次提交,login.Error,因为我可以看到“给用户名后没有给密码它是再次点击提交”。 –
在您的代码中的'密码'是静态类还是WebElement? – Buaban