あなたのwhileループはCPU使用量の大部分を占めます。 小さな変更はパフォーマンスを大幅に向上させます。あなたのケースでは
public bool StopWatchLoop<T>(Func<string, T> getMethod, string getData, T cond) where T : new()
{
var i = getMethod(getData);
var sw = new Stopwatch();
sw.Start();
while (Compare(i, cond) && sw.Elapsed < TimeSpan.FromSeconds(120))
{
i = getMethod(getData);
Thread.Sleep(50);
}
Trace.WriteLine($"Expected: {cond.ToString()} actual {i} - data: {getData}");
return (Compare(i, cond)) ? true : false;
}
private bool Compare<T>(T x, T y)
{
return EqualityComparer<T>.Default.Equals(x, y);
}
:
while(true)
{
if (!content.Text.Equals (driver.FindElementByXPath (myXPath).Text))
{
content = driver.FindElementByXPath (myXPath);
Console.WriteLine (content.Text);
Thread.Sleep(1); //add this code
}
}
は、私は次の方法をお勧めします。
StopWatchLoop<string>(getElementText, myXpath, Content.Text);
をサンプル上のコード要素120秒の最大時間中(真)があるので、:サンプラーと指揮変数として使用getメソッドは、今あなたが使用することができますexpcedテキスト
です悪い習慣。