0
votes

In selenium automation, I'm trying to execute jquery script in IE 11 browser but while executing the script it's throwing the below error. Also, the same code which is working in chrome browser with out any issues.

Below are the code:

IJavaScriptExecutor js = _driver as IJavaScriptExecutor;
string query = "return jQuery('#myID').parent();";
            var objElement = js.ExecuteScript(query);
            foreach (IWebElement element in (IEnumerable)objElement)
            {
                _webElement = element;
            }

enter image description here

at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.get_Text()

Note: Also, i tried some other script which is working in Ie browser.

Like click the button,

IJavaScriptExecutor js = _driver as IJavaScriptExecutor;
 string query = "return jQuery('#myID').parent().click();"
            var objElement = js.ExecuteScript(query);

Please help me on this.

Much apperciate your help.

1

1 Answers

0
votes

First things first, I would not recommend testing in IE. I found out, that the best Browser for testing is Google Chrome. Sometimes IE is just not able to find an element and its getting so annoying, that i focus my tests at Chrome and Firefox. Your Code looks like C#. You don't need to use JQuery to locate an object. You can use

driver.FindElement(By.Id("myid")).Click();

or you can use Selenium IDE ( a Firefox extension) witch generates great code in many languages automatically. It selects elements by XPath. I hope I was able to help you.