2017-01-28 9 views
0

標準のHTMLボタンをクリックしようとしています。ドライバが要素を正しく検索していて、Click()メソッドが例外なく完了しますが、クリックがブラウザで呼び出されていません。Selenium .NET Click()が動作しない

以下の例は、Googleホームページを開き、クリックする(またはクリックに失敗する)私は幸運を感じるボタンです。

private static readonly InternetExplorerOptions INTERNET_EXPLORER_OPTIONS = new InternetExplorerOptions 
{ 
    IgnoreZoomLevel = true 
}; 

[Test] 
public void Clicking() 
{ 
    using (var driver = new InternetExplorerDriver(INTERNET_EXPLORER_OPTIONS)) 
    { 
     driver.Navigate().GoToUrl("http://www.google.com"); 

     driver.FindElement(By.Name("btnI")).Click(); 

     Assert.That(driver.Url, Is.EqualTo("https://www.google.com/doodles")); 
    } 
} 

私はIEDriverServer.exeの32ビット版を使用しています。

私はIEのバージョン11.576.14393.0を使用しています。

アップデートバージョン:11.0.38

他の解決策は同じ(非)影響がありますが、有用なwaitの条件ElementToBeClickableが見つかりました。

+0

可能な重複[セレン/ Firefoxの:コマンド ".click()" 見つかった要素では動作しません](http://stackoverflow.com/questions/15294630/selenium-firefox-command-click -doesnt-with-a-found要素) – Tom

+0

ブラウザーに関係なく、セレニウムは見つかった要素をクリックできないことがあります。 1つの方法は、Javascript経由で、 'JavascriptExecutor'を使ってそれを試みることです。実行中の競合状態によって発生する可能性があるため、クリックする前に試してみることもできます。 – Tom

答えて

0

ExpectedConditions.ElementToBeClickable待ち状態を追加すると問題が解決しました。

[Test] 
public void Clicking() 
{ 
    using (var driver = new InternetExplorerDriver()) 
    { 
     driver.Navigate().GoToUrl("http://www.google.com"); 

     var button = driver.FindElement(By.Name("btnI")); 
     Assert.That(button.TagName, Is.EqualTo("input")); 

     var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
     wait.Until(ExpectedConditions.ElementToBeClickable(button)); 
     button.Click(); 
     wait.Until(webDriver => webDriver.Url == "https://www.google.com/doodles"); // <== wait until condition here 
     Assert.That(driver.Url, Is.EqualTo("https://www.google.com/doodles")); 
    } 
} 
関連する問題