I need to make sure that a certain website code contains a div like this one:
<div id="iframe-content"> some code here... </div>
I tried this way:
elementTry = doc.select("div#iframe-content");
and next I stored it into the String
String someText;
someText = elementTry.toString();
and tried to show the output via Toast, but it gives me "null". I am sure the website contains the div with this id, so
what can I do to fix it?
EDIT:
Toast code
Toast.makeText(getContext(), "Passed: "+ someText, Toast.LENGTH_LONG).show();
Try using this
elementTry = doc.select("div#iframe-content");
String someText;
someText = elementTry.text();
Hope this helps
Related
We are getting url from JSON Response and which we open in in Chrome.The page loads , there is submit button which we click then it redirect to url as :-
https://www.google.com/AB1234
We need the need to retrieve only "AB1234" value from url.
tried following code to get value ="AB1234"
String url = driver.getCurrentUrl();
int index=url.lastIndexOf("/");
String result = url.substring(0,index);
but here getting initial part of url:https://www.google.com/
You need to call substring function with index +1 .
Try below code :
String url = driver.getCurrentUrl();
int index = url.lastIndexOf("/");
String result = url.substring(index + 1);
To parse a URI, it's likely a good idea to use a URI parser.
Given http://example.com/bar
String path = URI.create(driver.getCurrentUrl()).getPath();
will get you '/bar'.
Given http://example.com/bar/mumble the same code gets '/bar/mumble'. It's unclear from your question whether this is what you want. Nevertheless, you should at least start the parse as above.
private void showAllUserData() {
Intent validation = getActivity().getIntent();
String user_username = validation.getStringExtra("username");
String user_email = validation.getStringExtra("email");
String user_password = validation.getStringExtra("password");
String user_name = validation.getStringExtra("name");
fullNameLabel.setText(user_name);
userNameLabel.setText(user_username);
fullname.getEditText().setText.toString(user_name);
email.getEditText().setText.toString(user_email);
password.getEditText().setText.toString(user_password);
}}
My get all user data method has a problem here, in the edit text to string section, I don't how to use it in a fragment.
here is how my code looks like in android studio
Please post your code as text and not as images next time. This article contains information on how to ask a good question on StackOverflow.
Are full_name_profile, email_profile and password_profile EditTexts in your XML layout? Because in that case, the variables fullname, email and password are already EditTexts and you can just remove getEditText() from your code and set the text like this: fullname.setText(user_username)
I would like to verify the partial value of a string I get from a web page. I give an example the string is "Incident 1946721 Updated" and I would like to insert a check that verifies that the two words Incident are present as prefix and Updated as suffix. how can I do?
the html code where the text is present this is:
<div class="modal-body"><button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button><div class="bootbox-body">Incident 1946721 Updated</div></div>
Use below code :
String value = driver.findElement(By.xpath("//div[#class='bootbox-body']")).getText();
if(value.startsWith("Incident") && value.endsWith("Updated")) {
System.out.println("Test Pass");
}else {
System.out.println("Test Fail");
}
Let me know if you have further query.
I connected to a website, used JSoup to find the "textfield" ID's, input the values, now i need to stream it out.
Can someone please help me with the correct coding to stream the "modified" doc back to the website?
if (source == enter2)
{
String URL = "http://www.clubvip.co.za/Login.aspx";
Element number;
Element pass;
Element keyword;
try {
Document doc = Jsoup.connect(URL).get();
number = doc.getElementById("ctl00_ContentPlaceHolder1_CellNumberRadText").attr("value", "number");
System.out.println(number);
pass = doc.getElementById("ctl00_ContentPlaceHolder1_PasswordRadText").attr("value", "password");
System.out.println(pass);
keyword = doc.getElementById("ctl00_ContentPlaceHolder1_KeyWordRadText").attr("value", "keyword");
System.out.println(keyword);
Why are you doing it like this?
If you need to login to that webpage, simply take arguments and send them via HTTP POST request to page where <form> points to
which is <form method="post" action="login.aspx">
Instead of what you are doing:
Jsoup.connect("http://www.clubvip.co.za/Login.aspx")//
.data("ctl00_ContentPlaceHolder1_CellNumberRadText", "number",
"ctl00_ContentPlaceHolder1_PasswordRadText", "password",
"ctl00_ContentPlaceHolder1_KeyWordRadText", "password").post();
not tested, so possibly not 100% correct...
I am retrieving all the contacts of a user from gmail and yahoo, I have added the checkbox, the user needs to select the desired email id to which he need to send email. I need to collect all user selected email id's and save them in a string send that string to another servlet where I am sending emails.
I was able to add the check box dynamically but I am not able to collect the emails and save them in a string. This is the code I have written to add check box before all the emails,
kindly help me to put those selected email id's in a string
I used the following code, but still I am not able to do it.You can have a look at the demo of this app http://ec2-50-16-183-101.compute-1.amazonaws.com/SocialAuthNew/
To get the contacts from Gmail type google in the text box and for yahoo type yahoo and click on submit button
List<Contact> contactsList = provider.getContactList();
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><script type='text/javascript'>");
out.println("function getAllContacts(size){ var selected_list='';");
out.println("for(var c=0;c<size;c++){if(document.getElementById('mailCheckbox'+c).checked==true){selected_list=selected_list+document.getElementById('lblmail'+c).innerHTML+':';}}");
out.println("document.getElementById('final_mailing_list').innerHTML=selected_list;}</script>");
out.println("<title></title>");
out.println("</head>");
out.println("<body>");
for(int i=0;i<contactsList.size();i++){
System.out.println(contactsList.get(i).getFirstName()+" : "+contactsList.get(i).getLastName()+":"+contactsList.get(i).getEmail());
out.println("<h1> Imported conatcts from your mail are:-</h1>");
out.println("<input type='checkbox' id='mailCheckBox"+i+"' name='mailCheckbox'></input>");
/* out.println(contactsList.get(i).getFirstName());
out.println(contactsList.get(i).getLastName());*/
out.println("<label id='lblmail"+i+"'>"+contactsList.get(i).getEmail()+"</label>");
}
int size=contactsList.size();
out.println("<input type='button' value='GetContact' onclick='getAllContacts("+size+");'/> ");
out.println("<div id='final_mailing_list'></div></body>");
out.println("</html>");
}
Try this:
1) Wrap your email in a DOM element to make it easier to access
out.println("<span>" + contactsList.get(i).getEmail() + "</span>");
2) Using something like e.g. JQuery for normalizing access to the DOM on the client, do
function getSelectedEmails() {
var emails = [];
$('body').find('input[name="mailCheckbox"]:checked').each(function() {
emails.push($(this).closest('span').text());
});
return emails;
}
This returns the emails in an array - which you can easily concatenate into a string if you want with e.g.
var emailString = emails.join(", ");
...although I think using an array is usually better (perhaps JSON encoded if you need to serialize it).
s using array is much easier. i have used array and gave the check box name as check1 and on the click of submit button i have called the following function. this function alerts the value of the selected check boxes and passes the action to servlet
<script>
function onCallForInterview()
{
var selectedIds;
var count=0;
for (i=0; i<document.frm.check1.length; i++)
{
if (document.frm.check1[i].checked==true)
{
if(count==0){
selectedIds=document.frm.check1[i].value;
count=count+1;
}
else
selectedIds=selectedIds+","+document.frm.check1[i].value;
}
}
alert(selectedIds);
document.frm.action="<%=contextPath%>/SearchCandInfo? action=selectcanforinterview&ids="+selectedIds;
document.frm.submit();
}
</script>
A slightly more primitive way to achieve this,
Create a bunch of Check-Box as you are doing now but with the difference that all of htem should have the same name i.e. do the following correction in your code
out.println("<input type='checkbox' id='mailCheckBox' name='mailCheckbox'></input>");
Now retrieve all the values of such text boxes on your server side using following call on request object,
String[] emailIds = request.getParameterValues("mailCheckBox");
Hope this helps.