Hi,
I have created a sample class file in C# to explore
WebDriverBackedSelenium (as shown below).
The question that I have is, when I try to fire an invalid method on
an element like in the example below where I try to fire Type on the
Google logo ‘hplogo’, instead of getting an exception which should be
caught in the try-catch block I get an error
‘System.InvalidOperationException was unhandled, Message="JavaScript
error (UnexpectedJavaScriptError)"’ which is not handled by the try
catch block. Is there some workaround to this issue where in I can get
a proper message in the try-catch block instead of the run being
halted?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using
OpenQA.Selenium.IE;
using OpenQA.Selenium.Firefox;
using Selenium;
namespace WindowsFormsApplication1
{
class Class1
{
IWebDriver driver;
ISelenium selenium;
public void Setup()
{
try
{
driver = new InternetExplorerDriver();
selenium = new WebDriverBackedSelenium(driver, "http://
www.google.co.in");
selenium.Start();
}
catch (Exception e)
{
Console.WriteLine("Setup", e);
}
}
public void Teardown()
{
driver.Quit();
}
public void TestSearchGoogle()
{
try
{
selenium.Open("
http://www.google.co.in");
selenium.Type("hplogo", "test");
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}
}
System.InvalidOperationException was unhandled
Message=JavaScript error (UnexpectedJavaScriptError)
Source=WebDriver
StackTrace:
at
OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver
\Remote\RemoteWebDriver.cs:line 985
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(DriverCommand
driverCommandToExecute, Dictionary`2 parameters) in c:\Projects
\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line
805
at
OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptInternal(String
script, Boolean async, Object[] args) in c:\Projects\WebDriver\trunk
\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 1019
at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String
script, Object[] args) in c:\Projects\WebDriver\trunk\dotnet\src
\WebDriver\Remote\RemoteWebDriver.cs:line 402
at
Selenium.Internal.SeleniumEmulation.JavaScriptLibrary.ExecuteScript(IWebDriver
driver, String script, Object[] args) in c:\Projects\WebDriver\trunk
\dotnet\src\Selenium.WebDriverBackedSelenium\Internal\SeleniumEmulation
\JavaScriptLibrary.cs:line 75
at
Selenium.Internal.SeleniumEmulation.Type.HandleSeleneseCommand(IWebDriver
driver, String locator, String value) in c:\Projects\WebDriver\trunk
\dotnet\src\Selenium.WebDriverBackedSelenium\Internal\SeleniumEmulation
\Type.cs:line 61
at
Selenium.Internal.SeleniumEmulation.SeleneseCommand.Apply(IWebDriver
driver, String[] args) in c:\Projects\WebDriver\trunk\dotnet\src
\Selenium.WebDriverBackedSelenium\Internal\SeleniumEmulation
\SeleneseCommand.cs:line 30
at Selenium.Internal.CommandTimer.RunCommand() in c:\Projects
\WebDriver\trunk\dotnet\src\Selenium.WebDriverBackedSelenium\Internal
\CommandTimer.cs:line 74
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: