Adding cookies to selenium from cookie container

倖福魔咒の 提交于 2020-12-10 09:11:09

问题


I have a data grid view which collects successful http requests. What I want to happen is when the button inside the data grid view is clicked it should open up a browser in selenium with the cookies from that specific http request. I have some of it already.

Here is a screenshot of the data grid view: https://imgur.com/a/5hs9l

Here is what I have so far:

CookieContainer cookiejar = new CookieContainer();
//Http request goes here
httpWebRequest1.CookieContainer = cookiejar;

This is used to add an item to cart and save the cookies in the cookie container.

This is what the checkout button does:

var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.adidas.co.uk/on/demandware.store/Sites-adidas-GB-Site/en_GB/Cart-Show");

foreach (System.Net.Cookie cook in response.Cookies)
{                    
driver.Manage().Cookies.AddCookie(new OpenQA.Selenium.Cookie(cook.Name, cook.Value));
}

What I want to happen is that each data grid view row has a different cookie container and when checkout is clicked it opens a browser using that cookie container. At the moment one of the problems is I can't make a working public cookie container that I can add the cookies from using the button. The second thing is I don't know how to make a separate container for each row.

Any help is appreciated even if you don't know the whole process.

来源:https://stackoverflow.com/questions/43592617/adding-cookies-to-selenium-from-cookie-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!