2016-03-01 79 views
0

我有一個場景,在那裏我點擊一個按鈕,彈出窗口出現,我需要點擊另一個按鈕。司機點擊頁面上的按鈕,並保持在同一元素,直到超時。我可以看到彈出窗口中的按鈕被選中,但沒有點擊。我嘗試使用CSS選擇器而不是XPath。嘗試使用SendKeys(「\ n」),Sendkeys(keys.ENTER)。沒有工作。IE 11點擊一個按鈕,並等到超時硒webdriver

我使用IE11,硒webdriver 2.52,Windows 8.1。

方法,其中司機等待:

public static void ImportThisFile() 
    { 
     try 
     { 
      new WebDriverWait(Drivers._driverInstance, TimeSpan.FromSeconds(2000)); 
      Drivers._driverInstance.FindElement(By.CssSelector("#import-this-file-button")).Click(); 
      Drivers._driverInstance.SwitchTo(); 
      new WebDriverWait(Drivers._driverInstance, TimeSpan.FromSeconds(2000)); 
      Drivers._driverInstance.FindElement(By.CssSelector(".btn.medium.left")).SendKeys(OpenQA.Selenium.Keys.Enter); //Drivers._driverInstance.FindElement(By.XPath(".//*[@id='process-file-form']/fieldset/div[3]/input")); 
      Drivers._driverInstance.SwitchTo().ParentFrame(); 
     } 
     catch(Exception e) 
     { 
      Drivers._driverInstance.FindElement(By.XPath("html/body/div[6]/div[1]/button")).Click(); ; 
      throw new Exception("Import pop up window: " + e); 
     } 
    } 

在堆棧跟蹤我越來越已逾時消息話題:

Test method SDTestAutomation.SDDirectPage_Tests.Upload_DuplicateData threw exception: 
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:56598/session/c627ffbd-21cf-47c2-abd8-6f7aa10516f5/element timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out 
TestCleanup method SDTestAutomation.SDDirectPage_Tests.QuitBrowser threw exception. System.Exception: System.Exception: Logout button is not clickedOpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:56598/session/c627ffbd-21cf-47c2-abd8-6f7aa10516f5/element timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out. 
at System.Net.HttpWebRequest.GetResponse() 
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 
--- End of inner exception stack trace --- 
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) 
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) 
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) 
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) 
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByLinkText(String linkText) 
at OpenQA.Selenium.By.<>c__DisplayClass6.<LinkText>b__4(ISearchContext context) 
at OpenQA.Selenium.By.FindElement(ISearchContext context) 
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) 
at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass3b.<ElementToBeClickable>b__3a(IWebDriver driver) 
at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition) 
at SmartDebitTestFramework.HomePage.get_Logout() in 
Result StackTrace: 
at System.Net.HttpWebRequest.GetResponse() 
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 
--- End of inner exception stack trace --- 
    at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 
    at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) 
    at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) 
    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) 
    at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) 
    at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath) 
    at OpenQA.Selenium.By.<>c__DisplayClasse.<XPath>b__c(ISearchContext context) 
    at OpenQA.Selenium.By.FindElement(ISearchContext context) 
    at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) 
    at SmartDebitTestFramework.SDDirectPage.ImportThisFile() in 

我都對IE設置的基本設置。我使用IE 32位,因爲64位非常慢。我能有任何建議擺脫這個問題嗎?沒有找到一個可行的解決方案給我在線。

InternetExplorerOptions options = new InternetExplorerOptions(); 
options.AddAdditionalCapability("IgnoreZoomLevel", true); 
options.AddAdditionalCapability("EnableNativeEvents", false); 
options.AddAdditionalCapability("UnexpectedAlertBehavior", "accept"); 
options.AddAdditionalCapability("EnablePersistentHover", true);   
options.AddAdditionalCapability("IntroduceInstabilityByIgnoringProtectedModeSettings", true); 
options.AddAdditionalCapability("RequireWindowFocus", true); 
//var options = new InternetExplorerOptions { EnableNativeEvents = false }; 
// options.AddAdditionalCapability("disable-popup-blocking", true); 
_driverInstance = new InternetExplorerDriver(path, options); 
// _driverInstance = new InternetExplorerDriver(path); 
_driverInstance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromTicks(500)); 
+0

這些功能都不會對驅動程序的設置產生任何影響。驅動程序使用的字符串與** InternetExplorerOptions對象的屬性名稱不同。使用屬性,而不是'AddAdditionalCapability'。 – JimEvans

回答

-1

我以兩種方式解決了我的問題。發佈解決方案,以便它可以幫助其他人。

解決方案1:

IWebElement element1 = Drivers._driverInstance.FindElement(locator); 
if (((RemoteWebDriver)Drivers._driverInstance).Capabilities.BrowserName == "internet explorer") 
{ 
    element1.SendKeys(Keys.Tab); 
    element1.SendKeys(Keys.Enter); 
} 
else 
{ 
    element1.Click(); 
} 

解決方法2:使用JavaScript

IWebElement element = Drivers._driverInstance.FindElement(By.Id("deauthorise-file-button")); 
if (((RemoteWebDriver)Drivers._driverInstance).Capabilities.BrowserName == "internet explorer") 
{ 
    IJavaScriptExecutor js = (IJavaScriptExecutor)Drivers._driverInstance; 
       js.ExecuteScript("arguments[0].click();", element); 
} 
else 
{ 
    element.Click(); 
} 

如果瀏覽器interner探險家,我們使用這些黑客的剩餘的瀏覽器,我們可以簡單地使用element.Click()。希望這可以幫助某人。

+0

Downvoting因爲沒有調查設置InternetExplorerOptions,特別是EnableNativeEvents屬性和RequireWindowFocus屬性。請參閱[本博文](http://jimevansmusic.blogspot.com/2013/01/revisiting-native-events-in-ie-driver.html)瞭解更多信息。 – JimEvans

+0

@JimEvans我用我的IE設置更新了我的問題。沒有什麼幫助我。正如你可以看到我的問題,我沒有得到任何其他解決方案。經過2個月的鬥爭,這是唯一對我有用的解決方案。如果你知道更好的方法,讓我知道我很高興嘗試它們。在我的自動化腳本中,IE11仍然存在一些問題,我只是無視它們,因爲我無法解決它們。我只是沒有提到InternetExplorerOptions和問題中的東西,只是提到了驅動程序實例。 – Sudeepthi

+0

請參閱我對編輯問題的評論。您嘗試添加的功能沒有一個對駕駛員的行爲有任何實際影響。 – JimEvans

0

如果您想單擊元素Sendkeys發送擊鍵而不是鼠標單擊。在名爲'acceptbutton'的彈出窗體上有一個屬性,您可以在該窗體上設置按鈕名稱,按下'enter'時該按鈕將被點擊。您可能要檢查的另一個屬性是「啓用」按鈕本身。這是用於Visual Studio窗體應用程序。我不知道你用這個驅動程序的東西做什麼。

+0

@agearge感謝您的回覆。我正在測試一個Web應用程序。我有幾個自定義構建彈出窗口,我需要與彈出窗口中的幾個元素進行交互。 Chrome和Firefox按預期工作。這是困擾我的IE瀏覽器。那麼我應該爲使用sendkeys的IE分開代碼嗎?如果這是唯一的方法,我需要更改很多代碼。 – Sudeepthi