Delete cookie selenium java - java

I understand that if I want to delete a cookie through Selenium I should do the next:
this.getDriverProvider().get().manage().deleteCookieNamed("cookie");
But, when I created this cookie I set:
Cookie cookie = new Cookie("name=cookie", "max_age=1200");
I found that if I want to delete this cookie, I have to pass name=cookie and not cookie alone. So, I don't understand how these pairs values are used then.
Please, can somebody help me?
Thanks,
Sarang

When you create a cookie, you're passing name=cookie as its name. Constructor parameters are ordered and are mapped to its corresponding attribute so you don't have to specify that the first parameter will be the cookie's name.
If you were to add a value AFTER the creation, you invoke a method that will set the value you use as the value of the key associated to the method. For example:
Cookie c = new Cookie("name", "value");
c.setVersion("cookieVersion"); //Here, the version key will have the "cookieVersion" value
c.setMaxAge(1200);
And then, when you invoke the getName() method you'll get the value associated to the key name, passed on the corresponding constructor. In your case is "name=cookie" and in my case is just "name".
If you feel like, you can check the documentation.

Related

How to write dynamic native queries in cosmos DB

I have a situation where i have couple of fields i have to pass while calling the cosmos DB , but those fields may not always have values. Some of them might be null while passing them to the repository method. I am trying to do it like below
public interface CachedRepository{
#Query(value="select * from abc a where (#base=null or a.base=#base) and (#position=null or a.position=#position) and (#active=null or a.active = #active)")
List<BackList> getBackListOptions(#Param("base")String base,#Param("position")String position,#Param("active") String active);
The implementation class
latestDetails = repositoryA.getBackListOptions(p.getBase(),p.getPosition(),p.getActive().get(0));//active is a List and we are passing one value
I am trying to pass the request without the active parameter(i.e. active is null in the request) The exception i am getting is
Can not invoke "java.util.List.get(int)" because the return value of request.Pick.getActive() is null
The cosmos Table is
{
'_id":"a25777-j"
"empId": 2436,
"base":"JH",
"position":"HG",
"active":"J"
.........
}
And i am taking reference from this answer
How to write dynamic sql in Spring Data Azure Cosmos DB
Please let me know where i am doing it wrong
The code you have given should work fine if either null or an actual value is passed for any of the parameters. But in your case, for active, it is neither. Nothing is passed, not even null.
It seems from the comments in your code that "active" is an object of type List, and you are attempting to pass a value in that list to getBackListOptions, and extracting that value directly in the method call with p.getActive().get(0). But I think your implementation code is failing where p.getActive().get(0) is called, before getBackListOptions is even invoked. The error you are getting is not something that is returned from Cosmos Spring client, which I believe is doing what it should. You need to handle the values you are passing properly before passing them. I think you could handle this something like below.
String base = p.getBase(); //set the value here so it is clear where failure is
String position = p.getPosition(); //set the value here so it is clear where failure is
String active = p.getActive() == null ? null : p.getActive().get(0); //I think this line was failing before because p.getActive() was null, but this condition handles that case
latestDetails = repositoryA.getBackListOptions(base,position,active);//active is a List and we are passing one value

How to retrieve an integer URL parameter with JSP? [duplicate]

In JSP how do I get parameters from the URL?
For example I have a URL www.somesite.com/Transaction_List.jsp?accountID=5
I want to get the 5.
Is there a request.getAttribute( "accountID" ) like there is for sessions or something similar?
About the Implicit Objects of the Unified Expression Language, the Java EE 5 Tutorial writes:
Implicit Objects
The JSP expression language defines a set of implicit objects:
pageContext: The context for the JSP page. Provides access to various objects including:
servletContext: The context for the JSP page’s servlet and any web components contained in the same application. See Accessing the Web Context.
session: The session object for the client. See Maintaining Client State.
request: The request triggering the execution of the JSP page. See Getting Information from Requests.
response: The response returned by the JSP page. See Constructing Responses.
In addition, several implicit objects are available that allow easy access to the following objects:
param: Maps a request parameter name to a single value
paramValues: Maps a request parameter name to an array of values
header: Maps a request header name to a single value
headerValues: Maps a request header name to an array of values
cookie: Maps a cookie name to a single cookie
initParam: Maps a context initialization parameter name to a single value
Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.
pageScope: Maps page-scoped variable names to their values
requestScope: Maps request-scoped variable names to their values
sessionScope: Maps session-scoped variable names to their values
applicationScope: Maps application-scoped variable names to their values
The interesting parts are in bold :)
So, to answer your question, you should be able to access it like this (using EL):
${param.accountID}
Or, using JSP Scriptlets (not recommended):
<%
String accountId = request.getParameter("accountID");
%>
In a GET request, the request parameters are taken from the query string (the data following the question mark on the URL). For example, the URL http://hostname.com?p1=v1&p2=v2 contains two request parameters - - p1 and p2. In a POST request, the request parameters are taken from both query string and the posted data which is encoded in the body of the request.
This example demonstrates how to include the value of a request parameter in the generated output:
Hello <b><%= request.getParameter("name") %></b>!
If the page was accessed with the URL:
http://hostname.com/mywebapp/mypage.jsp?name=John+Smith
the resulting output would be:
Hello <b>John Smith</b>!
If name is not specified on the query string, the output would be:
Hello <b>null</b>!
This example uses the value of a query parameter in a scriptlet:
<%
if (request.getParameter("name") == null) {
out.println("Please enter your name.");
} else {
out.println("Hello <b>"+request. getParameter("name")+"</b>!");
}
%>
Use EL (JSP Expression Language):
${param.accountID}
If I may add a comment here...
<c:out value="${param.accountID}"></c:out>
doesn't work for me (it prints a 0).
Instead, this works:
<c:out value="${param['accountID']}"></c:out>
request.getParameter("accountID") is what you're looking for. This is part of the Java Servlet API. See http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html for more information.
String accountID = request.getParameter("accountID");
www.somesite.com/Transaction_List.jsp?accountID=5
For this URL there is a method call request.getParameter in java , if you want a number here cast into int, similarly for string value cast into string. so for your requirement , just copy past below line in page,
int accountId =(int)request.getParameter("accountID");
you can now call this value useing accountId in whole page.
here accountId is name of parameter you can also get more than one parameters using this, but this not work. It will only work with GET method if you hit POST request then their will be an error.
Hope this is helpful.
example you wanted to delete the subject record with its subject_id
#RequestMapping(value="subject_setup/delete/{subjectid}",method = RequestMethod.GET)
public ModelAndView delete(#PathVariable int subjectid) {
subjectsDao.delete(subjectid);
return new ModelAndView("redirect:/subject_setup");
}
and the parameter will be used for input on your query
public int delete(int subjectid) {
String sql = "update tbl_subject set isdeleted= '1' where id = "+subjectid+"";
return template.update(sql);
}
page 1 :
Detail
page 2 :
<% String id = request.getParameter("userid");%>
// now you can using id for sql query of hsql detail product

how to pass value to VO which is inside map and VO

I have CompanyProfileVO in which I have declared companyProfile_addressVOMap as map of String and VO
i want to give value to the company_name which is present in side AddressIdentificationVO in the form of url encoded
How can I set value of company_name through url encoded form?
To get the value I'm using this
CompanyProfileVO.getCompanyProfile_addressVOMap().get("COMPANY").getCompany_name()
CompanyProfileVO.java
Map<String,AddressIdentificationVO> companyProfile_addressVOMap;
AddressIdentificationVO
#FormParam("company_name")
String company_name;
According to your Code you need to create two different Variable object 1 for json and 1 for XMl(URL encoded). you should pass your
Map<String,AddressIdentificationVO> companyProfile_addressVOMap;
AddressIdentificationVO inside JSONVO and call the JSON method When u hit the URL Encoded method .

SharedPreferences getString NULL parameter

Will I receive an error (Exception) on some devices if I set the second parameter of SharedPreferences.getString NULL?
SharedPreferences settings = ...
String data = settings.getString(_.PREFIX , null);
Will it cause an exception or an error on at least one device? Or I have to wrap this part of code in try-catch block?
If you are asking if you will get an exception if you set the second parameter to null, the answer is no (at least not unless you reference the result without first checking it is not null). The second parameter in the getString() method is the default value (i.e. the value that will be returned if there is nothing found for your prefix. So, it is perfectly acceptable to set null as your default value, as long as you realize (and account for) the fact that the value returned by your getString() could be null.
String data = settings.getString(_.PREFIX , null/Null here is default value/);
null - u can receive when your SraredPreferences have not this item(For example if u call/get this string before setting to this field any info or user clear cash of application from settings of device). I think it's can be normal situation, and u can remove "null" with some default value if you hope to got it(some emum field).
If u don't suppose get null validate data before using.
I thin'k your app must be ready get both variant, because user can change normal workflow.

how to get the location of the layout "R.Layou.*" if the id is given in the form of integer like "2131296340"

I am not getting to how to know to which layout it is point because instead of giving the full name like r.layout.activity_main it has given the id in the form of integer.
How to get the location if the integer id is given how to convert it?
use
getResources().getResourceName(int resid);
read more in that thread
To get the full id like R.id.your_id you have to make two calls:
getActivity().getResources().getResourceEntryName(int);
Which returns the identifier your_id
getActivity().getResources().getResourceTypeName(int);
Which returns the type of the resource like id, string, layout
As a note: Make sure the id with the corresponding value exists! Otherwise you will get a NotFoundException.

Categories

Resources