Unable to set cookies in Selenium Webdriver

后端 未结 5 977
名媛妹妹
名媛妹妹 2020-12-09 16:45

I\'m trying to add cookies to a link before I open it with webdriver but it keeps giving me this error:

org.openqa.selenium.UnableToSetCookieException

5条回答
  •  既然无缘
    2020-12-09 17:30

    You are creating the cookie before navigating to the site. If you are trying to create a cookie on the domain www.example.com, then you would want to navigate to some page on that domain, create the cookie, and then start your test.

    From my reading a while back, the best way to do this is to navigate to some page you know will not exist on the domain, e.g. www.example.com/this404page, then create the cookie. It should load a lot faster since it's an error page and shouldn't contain much content. After creating the cookie on the 404 page, start your test.

提交回复
热议问题