2

Local Machine: Dell Latitude (i7-8650U CPU @ 1.90GHz 2.11 GHz) with 16.0 GB RAM
Operating System: Windows 10 Pro (64-bit) v1909
Display Scale and Layout: 100%

Running on Visual Studio 2017 (v 15.9.21)
.NET Framework (v 4.8.03752)
Selenium NuGet package Selenium.WebDriver.IEDriver (v3.150.1) by jsakamoto

Internet Explorer 11, (v 11.836.18362.0) with Zoom = 100%

InternetExplorerOptions options = new InternetExplorerOptions();  
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;  
options.RequireWindowFocus = true;  
options.AddAdditionalCapability("disable-popup-blocking", true);  
options.EnablePersistentHover = true;  
options.EnsureCleanSession = true;  
options.EnableNativeEvents = false;  
options.UnhandledPromptBehavior = UnhandledPromptBehavior.Accept;  
options.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Top;  
options.IgnoreZoomLevel = true;  
options.EnsureCleanSession = true;  
options.AddAdditionalCapability("IE_ENSURE_CLEAN_SESSION", true);  
options.AddAdditionalCapability("JAVASCRIPT_ENABLED", true);

Classic ASP page
Element is an input element of type="button"

I instantiate the element using a factory, and the element variable name is "btnsearch" I then execute the following code and NONE of these approaches will trigger a Click event. Each approach appears to click the element, but the element doesn't seem to fire the click event through Selenium. If I physically click on the button, it fires the click event.

<code>
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("javascript:window.scrollBy(1119,3)"); // this is the coordinates of the element once scrolled into view  
IJavaScriptExecutor clicker = (IJavaScriptExecutor)driver;
clicker.ExecuteScript("arguments[0].click();", btnsearch);
driver.ExecuteJavaScript<object>("arguments[0].click();", btnsearch);  
Actions act = new Actions(driver);
act.MoveToElement(btnsearch).SendKeys(Keys.Enter).Build().Perform();  
btnsearch.Click();
</code>

I've even tried to add an event listener to send a keyup event (Enter key) and Selenium throws an exception "Object doesn't support property or method 'addEventListener'"

HELP PLEASE!!! I have searched extensively for a way to make this happen and have experimented with multiple variations of the IE Options (on and off) along with different coded methods. Unfortunately, the developers that work on this legacy app are unlikely to make any substantive updates until this app becomes sunsetted. What other things can I try? I'd even take a complicated workaround just to make my automation work until the sunset actually occurs.

  • Actions act = new Actions(driver); act.MoveToElement(btnsearch).click() – PDHide May 21 at 17:07
  • clicker.ExecuteScript("$(arguments[0]).click();", btnsearch); – PDHide May 21 at 17:10
  • Try this two and see if it's working ? – PDHide May 21 at 17:10
  • @PDHide The first suggestion did nothing, it behaves like all the other attempts. The second suggestion threw an exception "openqa.selenium.webdriverexception: error from javascript: access is denied." I don't have that much javascript experience, so I'm not sure where to start granting access. Thoughts? – rsasparilla May 21 at 18:07
  • @rsaparilla is the page fully loaded ? could you add a wait and check the button is clickable before executing the script – PDHide May 21 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.