Unable to set cookies in Selenium Webdriver

后端 未结 5 980
名媛妹妹
名媛妹妹 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条回答
  •  萌比男神i
    2020-12-09 17:43

    Adding cookies before navigating to the domain are called domain-less cookies which i believe is not possible.

    I have not found a way to drop a cookie before the url, but I think below scenario might help you out-

    1. Create a factory class to create webdriver instances
    2. Before returning the webdriver instance, navigating to any page on the domain under test, and drop the cookie, then navigate browser back.
    3. Your test can now begin, unaware that the navigation and cookie dropping has taken place

提交回复
热议问题