0
C#とAppiumでAndroidデバイスでネイティブアプリをテストしています。 要素が可視かどうかを確認しようとしています。 問題は、要素が見つからなかった場合、ドライバがテストを終了し、オブジェクトが見つかるまでページの最後にスワイプしたいということです。 オブジェクトはページの一番下にあります。 私はScrollToメソッドを使用していましたが、廃止されました。要素が見つからないときにドライバが終了する
public void SWipeUntilelementVisible()
{
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
bool visible = false;
int counter = 0;
while (visible == false)
{
if (counter > 0)
_driver.Swipe(1200, 1487, 1200, 732, 0);
if (isElementVisible(SendRequirement))
{
visible = true;
Console.WriteLine("Visible");
break;
}
}
}
public bool isElementVisible(IWebElement Elementid)
{
return SendRequirement.Displayed;
}
EDIT これは、オブジェクトを見つけるのに失敗した時に印刷されたのVisual Studioのログです。
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.NotImplementedException' in WebDriver.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'NUnit.Core.NUnitException' in nunit.core.dll
The thread 0x8a8 has exited with code 0 (0x0).
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
The thread 0x27d8 has exited with code 0 (0x0).
The thread 0x1fbc has exited with code 0 (0x0).
The thread 0x16cc has exited with code 0 (0x0).
The thread 0x19d0 has exited with code 0 (0x0).
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.InvalidOperationException' in WebDriver.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'NUnit.Core.NUnitException' in nunit.core.dll
The thread 0x1fd8 has exited with code 0 (0x0).
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
The thread 0x2380 has exited with code 0 (0x0).
The thread 0x19fc has exited with code 0 (0x0).
The thread 0x261c has exited with code 0 (0x0).
The thread 0x256c has exited with code 0 (0x0).
The thread 0x26cc has exited with code 0 (0x0).
The program '[8096] te.processhost.managed.exe' has exited with code 0 (0x0).
「カウンター」は何をする予定ですか?あなたのwhileループに入ります。あなたの例では、 'counter> 0はあなたの例ではfalseです。あなたの' counter'は0です。あなたの 'counter'は何もカウントせず、私は推測できますが、あなたのテストは5ドライバーがテストを終了します。 whileループの 'counter ++'が解決策になります。 – Maze
これはおそらく私の次のバグかもしれません。しかし、メインのバグは、実際に最初に入るときに発生します。 isElementVisibleから呼び出されている要素を検索すると、要素が見つからないためテストが失敗します。それはOKです。要素が見つからないときにスワイプを作成したいのです(その理由はループです)。残念ながら、要素が見つからないためテストは終了しています。 –
「テストが終了しています」と言ったとき、あなたはどういう意味ですか?例外がスローされますか?テストの成功/失敗/エラー? System.exit? NoSuchElementExceptionが表示されることは想像できます。これは、表示されている要素が表示されているかどうかをテストするだけで、要素が表示されているかどうかをテストするためです。要素SendRequirementはどこにありますか?たぶん[that](http://stackoverflow.com/questions/10934305/selenium-c-sharp-webdriver-how-to-detect-if-element-is-visible)もあなたを助けることができます。 – Maze