本文整理汇总了Java中org.openqa.selenium.Cookie.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.getName方法的具体用法?Java Cookie.getName怎么用?Java Cookie.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.Cookie
的用法示例。
在下文中一共展示了Cookie.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCookies
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* Get all the cookies for the current domain. This is the equivalent of calling "document.cookie" and parsing the result
*
* @return {@link com.axway.ats.uiengine.elements.html.Cookie Cookie}s array
*/
@PublicAtsApi
public com.axway.ats.uiengine.elements.html.Cookie[] getCookies() {
Set<Cookie> cookies = webDriver.manage().getCookies();
com.axway.ats.uiengine.elements.html.Cookie[] cookiesArr = new com.axway.ats.uiengine.elements.html.Cookie[cookies.size()];
int i = 0;
for (Cookie c : cookies) {
cookiesArr[i++] = new com.axway.ats.uiengine.elements.html.Cookie(c.getName(),
c.getValue(),
c.getDomain(),
c.getPath(),
c.getExpiry(),
c.isSecure());
}
return cookiesArr;
}
示例2: getHttpCookieString
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
public static String getHttpCookieString(Set<Cookie> cookies){
if(cookies==null){
return "";
}
String httpCookie="";
int index=0;
for(Cookie c:cookies){
index++;
if(index==cookies.size()){
httpCookie+=c.getName()+"="+c.getValue();
}else{
httpCookie+=c.getName()+"="+c.getValue()+"; ";
}
}
return httpCookie;
}
示例3: writeFile
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
public static void writeFile(String fileName, Set<Cookie> cookies) {
try {
File file = new File(fileName);
FileWriter fileWriter = new FileWriter(file);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
for (Cookie cookie : cookies) {
String strCookie = cookie.getName() + ";" + cookie.getValue() + ";" + cookie.getDomain() + ";"
+ cookie.getPath() + ";" + cookie.getExpiry() + ";" + cookie.isSecure() + ";"
+ cookie.isHttpOnly();
bufferedWriter.write(strCookie);
bufferedWriter.newLine();
}
bufferedWriter.flush();
bufferedWriter.close();
fileWriter.close();
LogUtils.info("写文件[" + fileName + "]操作成功");
} catch (Exception e) {
LogUtils.error("写文件[" + fileName + "]操作失败: " + e.getMessage());
e.printStackTrace();
}
}
示例4: shareCookies
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* Share the cookies with HttpClientTask
*/
public void shareCookies(){
Object store = getCookieStore();
if (store == null){
store = new BasicCookieStore();
this.getParametersInner().put(HttpClientTask.PARAM_HTTP_COOKIES, store);
}
CookieStore cookieStore = (CookieStore)store;
for (Cookie cookie : this.getDriver().manage().getCookies()){
BasicClientCookie newCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
newCookie.setDomain(cookie.getDomain());
newCookie.setPath(cookie.getPath());
newCookie.setExpiryDate(cookie.getExpiry());
newCookie.setSecure(cookie.isSecure());
cookieStore.addCookie(newCookie);
}
}
示例5: convertCookie
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* Converts Selenium cookie to Apache http client.
* @param browserCookie selenium cookie.
* @return http client format.
*/
protected ClientCookie convertCookie(Cookie browserCookie) {
BasicClientCookie cookie = new BasicClientCookie(browserCookie.getName(), browserCookie.getValue());
String domain = browserCookie.getDomain();
if (domain != null && domain.startsWith(".")) {
// http client does not like domains starting with '.', it always removes it when it receives them
domain = domain.substring(1);
}
cookie.setDomain(domain);
cookie.setPath(browserCookie.getPath());
cookie.setExpiryDate(browserCookie.getExpiry());
cookie.setSecure(browserCookie.isSecure());
if (browserCookie.isHttpOnly()) {
cookie.setAttribute("httponly", "");
}
return cookie;
}
示例6: seleniumCookiesToCookieStore
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* Get Cookie from WebDriver browser session.
*
* @return cookieStore from WebDriver browser session.
*/
private static CookieStore seleniumCookiesToCookieStore() {
Set<Cookie> seleniumCookies = WebDriverWrapper.getDriver().manage().getCookies();
CookieStore cookieStore = new BasicCookieStore();
for (Cookie seleniumCookie : seleniumCookies) {
BasicClientCookie basicClientCookie =
new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
basicClientCookie.setDomain(seleniumCookie.getDomain());
basicClientCookie.setExpiryDate(seleniumCookie.getExpiry());
basicClientCookie.setPath(seleniumCookie.getPath());
cookieStore.addCookie(basicClientCookie);
}
return cookieStore;
}
示例7: execute
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* 获取验证码
* @param engine 引擎
* @param param 例如:data,http://localhost:8080/G2/captcha!getLastCode.do
* @return 验证码
*/
public static String execute(SeleniumEngine engine, String param)
{
WebDriver driver = engine.getDriver();
Options manage = driver.manage();
String[] paramArray = param.split(",", 2);
if(paramArray.length != 2)
{
throw new RuntimeException("Param format is error, should be 'data,url'");
}
String key = paramArray[0];
String url = paramArray[1];
Set<Cookie> cookies = manage.getCookies();
List<AtCookie> atCookieList = new ArrayList<AtCookie>();
for(Cookie cookie : cookies)
{
String name = cookie.getName();
String value = cookie.getValue();
AtCookie atCookie = new AtCookie();
atCookie.setName(name);
atCookie.setValue(value);
atCookie.setPath(cookie.getPath());
atCookie.setDomain(cookie.getDomain());
atCookieList.add(atCookie);
}
String code = HttpApiUtil.getJsonValue(url, atCookieList, key);
return code;
}
示例8: setCookies
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
public static void setCookies(WebDriver driver,Set<Cookie> cookies){
if(cookies==null){
return;
}
//Phantomjs存在Cookie设置bug,只能通过js来设置了。
StringBuilder sb=new StringBuilder();
for(Cookie cookie:cookies){
String js="document.cookie=\""+cookie.getName()+"="+cookie.getValue()+";path="+cookie.getPath()+";domain="+cookie.getDomain()+"\";";
sb.append(js);
}
((JavascriptExecutor)driver).executeScript(sb.toString());
}
示例9: mimicCookieState
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
*
* @param seleniumCookieSet
* @return
*/
private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) {
BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
for (Cookie seleniumCookie : seleniumCookieSet) {
BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
duplicateCookie.setDomain(seleniumCookie.getDomain());
duplicateCookie.setSecure(seleniumCookie.isSecure());
duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
duplicateCookie.setPath(seleniumCookie.getPath());
mimicWebDriverCookieStore.addCookie(duplicateCookie);
}
return mimicWebDriverCookieStore;
}
示例10: getWebDriverCKSet
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
public static void getWebDriverCKSet(WebDriver webDriver,String name){
Set<Cookie> cookies =webDriver.manage().getCookies();
String ckStr = "";
for(Cookie c:cookies){
if("".equals(ckStr)){
ckStr=c.getName()+"="+c.getValue();
}else{
ckStr=ckStr+"; "+c.getName()+"="+c.getValue();
}
}
CKUtils.map.put(name, ckStr);
System.out.println("登录后的ck==="+ckStr);
}
示例11: writeCookieToFile
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* 把cookie追加写入cookie文件
*
* @param isDeleteFirst 是否先删除cookie文件
*/
public static void writeCookieToFile(Cookie cookie, boolean isDeleteFirst) {
String strCookie = cookie.getName() + ";" + cookie.getValue() + ";" + cookie.getDomain() + ";"
+ cookie.getPath() + ";" + cookie.getExpiry() + ";" + cookie.isSecure() + ";" + cookie.isHttpOnly();
if (isDeleteFirst) {
FileUtils.deleteFile(cookiePath);
FileUtils.createFile(cookiePath);
}
FileUtils.writeFile(cookiePath, strCookie);
}
示例12: apply
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
@Override
public String apply(Cookie input) {
String cookieName = null;
if (input != null) {
cookieName = input.getName();
}
return cookieName;
}
示例13: mimicCookieState
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* Load in all the cookies WebDriver currently knows about so that we can mimic the browser
* cookie state
*
* @param seleniumCookieSet
* Set<Cookie>
*/
private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) {
BasicCookieStore copyOfWebDriverCookieStore = new BasicCookieStore();
for (Cookie seleniumCookie : seleniumCookieSet) {
BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
seleniumCookie.getValue());
duplicateCookie.setDomain(seleniumCookie.getDomain());
duplicateCookie.setSecure(seleniumCookie.isSecure());
duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
duplicateCookie.setPath(seleniumCookie.getPath());
copyOfWebDriverCookieStore.addCookie(duplicateCookie);
}
return copyOfWebDriverCookieStore;
}
示例14: mimicCookieState
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
/**
* Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
*
* @param seleniumCookieSet Set<Cookie>
*/
private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) {
BasicCookieStore copyOfWebDriverCookieStore = new BasicCookieStore();
for (Cookie seleniumCookie : seleniumCookieSet) {
BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
duplicateCookie.setDomain(seleniumCookie.getDomain());
duplicateCookie.setSecure(seleniumCookie.isSecure());
duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
duplicateCookie.setPath(seleniumCookie.getPath());
copyOfWebDriverCookieStore.addCookie(duplicateCookie);
}
return copyOfWebDriverCookieStore;
}
示例15: getCookies
import org.openqa.selenium.Cookie; //导入方法依赖的package包/类
public List<CookieItem> getCookies() {
Set<Cookie> cookies = driver.manage().getCookies();
if (CollectionUtils.isEmpty(cookies))
return null;
List<CookieItem> cookieList = new ArrayList<CookieItem>(cookies.size());
for (Cookie cookie : cookies) {
BasicClientCookie basicCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
basicCookie.setDomain(cookie.getDomain());
basicCookie.setExpiryDate(cookie.getExpiry());
basicCookie.setPath(cookie.getPath());
basicCookie.setSecure(cookie.isSecure());
cookieList.add(new CookieItem(basicCookie));
}
return cookieList;
}