2016-08-26 16 views
0

私たちは、このようなダッシュボードページのオフウィジェットを呼び出すオブジェクトをすべてクリアするでしょう明確なダッシュボードのステップを記述しようとしている:Selenium Chromeドライバがスクロールバー以下の要素を検出できないのはなぜですか?

public static void ClearDashboard(string widgetToKeep = null) 
    { 
     var widgets = Driver.FindElements(
      By.XPath(
       $"//div[@widget-name and descendant::span[@class='title' and text()[not(contains(., '{widgetToKeep ?? "dummyText"}'))]]]" 
      )); 

     if (widgets != null) 
     { 
      foreach (IWebElement widget in widgets) 
      { 
       var closeButton = widget.FindElement(By.XPath(".//span[@class='delete']")); 
       closeButton.Click(); 
      } 
    } 

それは完全に動作します。 それはタイトルに戻ってすべてのスパンの要素を取得し、私は、これらの要素によってロールスパンがそれぞれのボタンを削除し得る、としてウィジェットを削除することができます。少しオフになっているウィジェットオブジェクトを除き

closeButton.Click() 

画面の ウィジェットが少し画面外にある場合、スパンボタンを見つけることができないようです。

This is the exception: InvalidOperation was unhandled by user code

An exception of type 'System.InvalidOperationException' occurred in WebDriver.dll but was not handled in user code

Additional information: unknown error: Element is not clickable at point (951, 760). Other element would receive the click: <div class="scroll" ng-class="{'getting-data': gettingNewData}" scroll-pag="">...</div>

(Session info: chrome=52.0.2743.116)

(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.1.7601 SP1 x86_64)

答えて

0

あなたはIJavascriptExecutorを使用して、クリックする前に、すべての要素に到達し、以下のようにWebDriverWaitを使用してクリック可能であることを要素になるまで待つようにスクロールを使用する必要があります -

IWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(3)); 
IJavaScriptExecutor js = Driver as IJavaScriptExecutor; 
foreach (IWebElement widget in widgets) 
{ 
var closeButton = widget.FindElement(By.XPath(".//span[@class='delete']")); 

//Now scroll to this element first 
js.ExecuteScript("arguments[0].scrollIntoView(true);", closeButton); 

wait.Until(ExpectedConditions.ElementToBeClickable(closeButton)).Click(); 
} 
+0

いいえ、あなたはいけません。 WebDriverは、「要素を暗黙的にスクロールして表示する」という仕様で自動的にこれを行うことになっています。©https://www.w3.org/TR/webdriver/#element-interaction –

関連する問題