IE 11 clicks on a button and waits until time out selenium webdriver

别等时光非礼了梦想. 提交于 2019-12-02 08:18:43

If you want to click the element Sendkeys sends keystrokes not mouse clicks. There is an attribute on a popup form called 'acceptbutton' on which you can set to a button name and that button will be clicked when 'enter' is pressed. Another attribute you might want to check is 'Enabled' on the button itself. This is for visual studio forms applications. I dont know what your doing with this driver stuff.

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

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!