Not able to add cookies from Internet Explorer driver in Selenium WebDriver with C#

765 views
Skip to first unread message

Srinivasan Sampath

unread,
Aug 16, 2013, 6:50:46 AM8/16/13
to seleniu...@googlegroups.com
Hi,

I am automating a scenario by using Specflow with Selenium WebDriver in C#. I need to set the cookies and access them in our automation test.

The scenario works fine with Firefox and Chrome. But it fails in Internet Explorer.

Code where the exception is captured.

var cookie = new Cookie("test", "currencyid=1");
Driver.Manage().Cookies.AddCookie(cookie);

Getting the following exception stack trace,

OpenQA.Selenium.NoSuchElementException : Unable to add cookie to page
TearDown : OpenQA.Selenium.NoSuchElementException : Unable to add cookie to page
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at com.Web.UI.AcceptanceTests.Common.WebStepsContext.ResetCurrencyIdIncomCookie() in WebStepsContext.cs: line 332
   at com.Web.UI.AcceptanceTests.Common.WebBasePageObject.DeleteAndRecreatecomCookie() in WebBasePageObject.cs: line 53
   at com.Web.UI.AcceptanceTests.Steps.MyAccountPageSteps.GivenIAmOnTheSiginPageForOpeningMyAccountPage() in MyAccountPageSteps.cs: line 76
   at com.Web.UI.AcceptanceTests.Steps.MyAccountPageSteps.GivenIAmAnExistingUser() in MyAccountPageSteps.cs: line 176
   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, ref TimeSpan duration)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
   at com.Web.UI.AcceptanceTests.Features.Secure.UserAccountFeature.ScenarioCleanup() in UserAccount.feature.cs: line 0
   at com.Web.UI.AcceptanceTests.Features.Secure.UserAccountFeature.VerifyDuplicateGiftVoucherCannotBeAddedToTheSameUserAccount(String errorMessage, String[] exampleTags) in UserAccount.feature: line 251
--TearDown
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at com.Web.UI.AcceptanceTests.Common.WebStepsContext.DeleteAllCookies() in WebStepsContext.cs: line 128
   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, ref TimeSpan duration)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType bindingEvent)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioEnd()
   at com.Web.UI.AcceptanceTests.Features.Secure.UserAccountFeature.ScenarioTearDown() in UserAccount.feature.cs: line 0

Selenium WebDriver Version : 2.33.0.0
Specflow Version : 1.9.0.77
Internet Explorer Browser Version : 9.0.8112.16421
Internet Explorer WebDriver Version: 2.25.3.0

Please let me know if you need any more input from my end.

Best Regards,

Srinivasan.S

Mark Collin

unread,
Aug 19, 2013, 9:47:14 AM8/19/13
to seleniu...@googlegroups.com
Did you load the web page before trying to add a cookie?

If I remember correctly IEDriver cannot add cookies until the website is
loaded.
> --
> You received this message because you are subscribed to the Google
> Groups "Selenium Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to selenium-user...@googlegroups.com.
> To post to this group, send email to seleniu...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/selenium-users/339ac31e-f323-4b52-8057-95f2050a7f5d%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages