この質問を設定する前に私は既にStaleElementReference Exception in PageFactoryを見ていましたが、問題が解決していないようです。ページリフレッシュ後にSeleniumがボタンをクリックできなくなった
私は、エラーメッセージ
OpenQA.Selenium.StaleElementReferenceException解決の問題が午前:古い要素 参照:要素がページの文書に添付されていませんが。
私は、問題を引き起こしている正確に何を知っているが、それを解決する方法を見つける傾けます。
以下のコードで概要を説明します。私はブラウザを更新
- 、
- は、アドレスが更新されたことを確認します。
次に、元のアドレスデータを再入力してクリーンアップします。しかし、[アドレスの更新]ボタンをクリックしようとすると、ページには表示されなくなりました(表示されていますが)。私はフレームワークとしてページファクトリモデルを使用しています。私はエラーを解決するために、私は再び要素を見つける必要があることを理解していますが、私はこれを行う方法を考え出すことはできません。どんな方法を使っていても、私がテストしているサイトで何度も繰り返す気がするのであれば、私の全体の枠組みにそれを適用できる必要があります。
マイコード
テストでエラーが発生しました。テストで
public void UpdateAccountAddress(string testName)
{
var testData = ExcelDataAccess.GetTestData(testName);
AddressLine1.EnterText(testData.AddressLine1, "AddressLine1");
AddressLine2.EnterText(testData.AddressLine2, "AddressLine2");
AddressLine3.EnterText(testData.AddressLine3, "AddressLine3");
City.EnterText(testData.City, "City");
AccountPostcode.EnterText(testData.AccountPostcode, "AccountPostcode");
UpdateDetails.ClickOnIt("UpdateButton");
}
クリックして、その上に拡張
最後にpublic static void ClickOnIt(this IWebElement element, string elementName)
{
element.Click();
Console.WriteLine("Clicked on " + elementName);
}
私のページクラスを、そのボタンを使用して、エラー
[FindsBy(How = How.CssSelector, Using = "#myAccountForm > div:nth-child(3) > button")]
[CacheLookup]
private IWebElement UpdateDetails { get; set; }
を引き起こしている
[Test]
public void Change_Account_Address()
{
Page.headerView.ClickOnLogin();
Page.loginPage.EnterUserNameandPasword(_testName);
Page.accountPage.ConfirmAtAccountPage(_testName);
Page.accountPage.UpdateAccountAddress(_testName);
Browsers.Refresh();
Page.accountPage.ConfirmAddressisUpdated(_testName);
Page.accountPage.UpdateAccountAddress("ResetAccountAddress"); - Error occurs on this step.
Page.accountPage.LogOut();
}
アカウントページボタン
public class Page
{
private static T GetPage<T>() where T : new()
{
var page = new T();
PageFactory.InitElements(Browsers.getDriver, page);
return page;
}
public static AccountPage accountPage
{
get
{
return GetPage<AccountPage>();
}
}
}
要素の前にいくつかの待機メソッドを置いてみましたか(ここでは**更新**ボタン)? –
PageFactoryの[StaleElementReference Exception]の重複の可能性があります(https://stackoverflow.com/questions/44838538/staleelementreference-exception-in-pagefactory) – DebanjanB
https://stackoverflow.com/questions/44838538/staleelementreference-exception-in -pagefactoryは、そのページに表示されているソリューションのうち、私のために働いているもの以外の類似した質問です。 –