渡されるインデックスに基づいてリストからIWebElementを取得する関数があります。ここで関数が範囲外の例外をスローし続ける
は財産である - ここで
public IList<IWebElement> ExistingDrafts { get { return Driver.FindElements(By.ClassName("broadcast-list-item")); } }
はここで機能 -
public void DeleteDraft(int index = 0) {
if(ExistingDrafts.Count > 0) {
ExistingDrafts[index].Click();
}
IWebElement discardButton = Driver.FindElement(By.XPath("/html/body/div[2]/div/div[1]/div[2]/div/div[2]/form/div[7]")).FindElements(By.ClassName("form-control"))[0];
Wait.Until(w => discardButton != null);
discardButton.Click();
}
である私が通過デバッグするとき、それは私のテスト -
[Fact]
public void DeleteTheDraft() {
BroadcastPage.DraftsHyperLink.Click();
//delete first draft
string firstDraftSubj = BroadcastPage.ExistingDrafts[0].Text;
System.Threading.Thread.Sleep(6000);
BroadcastPage.DeleteDraft(0);
string newfirstDraftSubj = BroadcastPage.GetNewestDraftSubject();
BroadcastPage.Wait.Until(w => newfirstDraftSubj != null);
Assert.True(firstDraftSubj != newfirstDraftSubj, "Draft was not deleted");
}
に使用されているどのようにされて私のテスト、それは合格する。しかし、テストを実行すると例外がスローされます。私は何が起こっているのか分からない。
あなたは 'ExistingDrafts'が要素を持っていることを確認してくださいではなく、つまり*十分な*の要素を持っています。 – DavidG
discardButton.Click()とは何ですか?行う? – EJoshuaS
@DavidGあなたは私のif条件を参照していますか?私はそれがデータを自分のリストに入れるのにどれくらいの時間がかかるかというタイミングの問題だと思った。 –