IE 11单击按钮并等待,直到硒Webdriver超时 [英] IE 11 clicks on a button and waits until time out selenium webdriver

查看:191
本文介绍了IE 11单击按钮并等待,直到硒Webdriver超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,我单击一个按钮,然后出现一个弹出窗口,我需要单击另一个按钮.驱动程序单击页面中的按钮,并且停留在同一元素上直到超时.我可以看到弹出菜单中的按钮已被选中但未被单击.我尝试使用CSS选择器而不是XPath.使用SendKeys("\ n"),Sendkeys(keys.ENTER)进行了尝试.什么都没用.

I have a scenario, where I click a button and a pop up appears, where I need to click another button. Driver is clicking on the button in the page, and with stay's on the same element until timedout. I can see that the button in the pop up is selected but not clicked. I tries using CSS selector instead of XPath. Tried using SendKeys("\n"), Sendkeys(keys.ENTER). Nothing worked.

我正在使用IE11,Selenium WebDriver 2.52,Windows 8.1.

I'm using 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);
        }
    }

在堆栈跟踪中,我收到超时消息:

In the stack trace i'm getting timedout messsage:

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位非常慢.我有什么建议可以摆脱这个问题吗?在网上找不到适合我的解决方案.

I have all the basic settings for IE set. I'm using IE 32 bit as 64 bit is very very slow. Can I have any suggestions to get out of this issue? Didn't find a workable solution for me Online.

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));

推荐答案

我用2种方法解决了我的问题.发布解决方案,这样可能会对其他人有所帮助.

I solved my problem in 2 ways. Posting the solution so it might help others.

解决方案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

Solution 2: Using 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();
}

如果浏览器是内部浏览器,那么我们将这些hack用于其余的浏览器,我们只需使用 element.Click().希望这对某人有帮助.

If the browser is interner explorer we use these hacks for the remaining browser we can simply use element.Click(). Hope this helps someone.

这篇关于IE 11单击按钮并等待,直到硒Webdriver超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆