3

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.

13
  • Actions act = new Actions(driver); act.MoveToElement(btnsearch).click()
    – PDHide
    Commented May 21, 2020 at 17:07
  • clicker.ExecuteScript("$(arguments[0]).click();", btnsearch);
    – PDHide
    Commented May 21, 2020 at 17:10
  • Try this two and see if it's working ?
    – PDHide
    Commented May 21, 2020 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? Commented May 21, 2020 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
    Commented May 21, 2020 at 18:39

1 Answer 1

1

Since you are using the JSE you don't need to scroll to the element (JS can interact with elements not in the ViewPort). You could just use the JSE to click the search button.

// declare JSE
// run JS to click the `button`
// (important) wait for the new page/element before proceeding

OR you can just use your JSE to run Element.scrollTo() and then do the normal Selenium Actions (which I would prefer since Selenium has helpers in their commands like click waits for page loads unlike JSE .click)

// declare JSE
// run JSE to scrollTo
// webDriver.click(myElement)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.