How to enable cookie in phantomjsdriver selenium c#?
RFC 2109 explicitly forbids cookie accepting from URLs with IP address
You are almost certainly accessing your test server via an IP based address.
You can try set up some kind of DNS/host file to allow you to use a fake domain name.
You must wait while page was loaded and then set cookie:
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//Wait page loadedcookieJar.AddCookie(new Cookie("x", "12345"));
Try this solution: https://stackoverflow.com/a/30636987
driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//some fake urldriver.Manage().Window.Maximize();driver.SwitchTo().ActiveElement();cookieJar.AddCookie(new Cookie("x", "12345"));driver.Navigate().GoToUrl(SeleniumConfiguration.Current.BaseURL);//cookie exsist
You can try below steps
1) Create a user profile on firefox or in chrome browser. 2) Confirm that "accept cookies" option is enabled by going to browsers settings option. 3) Load your profile via selenium.
Doing so it will ensure that enable cookie option is ON and your sessions would also get saved in the browser cache.
for chrome
System.setProperty("webdriver.chrome.driver", "browser/chromedriverlinux");ChromeOptions options = new ChromeOptions();options.addArguments("--user-data-dir=/home/rohit/.config/google-chrome/Profile 1");options.addArguments("--start-maximized");WebDriver driver = new ChromeDriver(options);
For Firefox
ProfilesIni profile = new ProfilesIni();FirefoxProfile ffprofile = profile.getProfile("ROHIT");WebDriver driver = new FirefoxDriver(ffprofile);
To create profile in firefox try below command in terminalfirefox -p