我在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