2016-03-01 119 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