我有一个场景,我点击一个按钮,弹出一个弹出窗口,我需要点击另一个按钮。驱动程序正在单击页面中的按钮,并且在同一元素上保持不变直到超时。我可以看到弹出窗口中的按钮被选中但未点击。我尝试使用CSS选择器而不是XPath。尝试使用SendKeys(" \ n"),Sendkeys(keys.ENTER)。没有任何效果。
我使用IE11,selenium 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 :(得分:0)
如果要单击元素Sendkeys发送击键而不是鼠标单击。弹出窗体上有一个名为“acceptbutton”的属性,您可以在其上设置按钮名称,按下“enter”时将单击该按钮。您可能要检查的另一个属性是按钮本身的“已启用”。这适用于visual studio表单应用程序。我不知道你用这个驱动程序做了什么。
答案 1 :(得分:-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();
}
如果浏览器是内部浏览器,我们将这些黑客用于剩余的浏览器,我们可以简单地使用 element.Click()。希望这有助于某人。