Im using Sahi OS to look for emails in mailtrap shared inbox.
I can navigate to the folder, search for an email containing a string, do whatever has to be done and logout.
The issue is the speed.. It takes about 1 second for each step in navigation, thats OK. As soon as Sahi gets to the Inbox, it takes about 1-2 minutes for each step in search procedure.
here is my .sah
// Mailtrap check
loginMailtrap($mailtrapId, $mailtrapPwd);
gotoSharedInboxes();
checkForSmsTicketNumber($ticketNumber);
logoutMailtrap();
// Functions
function loginMailtrap($id, $pwd){
_navigateTo($mailtrapUrl);
_setValue(_emailbox("/email/"), $id);
_setValue(_password("/password/"), $pwd);
_click(_submit("Log in"));
_assert(_isVisible(_heading2("/My Inboxes/")));
}
function gotoSharedInboxes();
_click(_span("/Shared Inboxes/"));
_click(_span("Shared Inbox Name"));
}
function checkForSmsTicketNumber($tn){
var $smsTn = $tn.substr(5)
_log($smsTn);
var $go = true;
var $counter = 0;
while ($go) {
var $elm = _span(0, _in(_listItem($counter, _in(_list("messages_list inbox-content nav-list")) ) ));
var $elmText = _getText($elm);
_log($elmText);
var $index = $elmText.indexOf($smsTn);
if($index == -1){
$go = true;
$counter++;
} else {
$go = false;
_click($elm);
_assert(_isVisible($elm));
}
}
}
function logoutMailtrap(){
_click(_div("/username/"));
_click(_link("/Logout/"));
}
The email that Im looking for is the first in the list.
Step _log($smsTn) takes 2 minutes to complete after _click(_span("Shared Inbox Name"));
then it takes about 2 minutes for _log($elmText);
then 2 minutes for _click($elm);
then 2 minutes for logoutMailtrap();
Any ideas is Sahi parses mailtrap so slowly? Something todo with websockets? I dont have that issue with other sites. Thanks!
Related
I am making the payment using authorize.net weblink "https://test.authorize.net/gateway/transact.dll" on the sharepoint page.
After filling in the information and making the payment it doest not redirect the page on x_relay_url. Instead, it shows the error of "Sorry something went wrong" as below.
I tried to make the payment using sandbox account. it makes the payment transaction however after transaction it does not redirect on URL instead it shows the error.
var fingerprint1;
var amount1 = "95.00";
$(document).ready(function(){
});
function setFormAction(button) {
var theForm = $(button).parents('form:first')[0];
//sandbox
var loginid = "99NSdk8a"
var txnkey = "9s54MPz333NcVUm5"
//Randomize
var sequence = parseInt(1000 * Math.random());
var tstamp = GetSecondsSince1970 ()
//added for student rate--CHANGE THIS TO USE VARIABLES SET AT PAGE LOAD
if (theForm.student.checked) {
amount1 = "0.05";
} else {amount1 = "95.00"}
// set form action
if (theForm.payment_type[0].checked){
//theForm.action = "https://secure.authorize.net/gateway/transact.dll";
theForm.action = "https://test.authorize.net/gateway/transact.dll";
theForm.method="POST"
} else {
theForm.action = "http://trainingcenter.umaryland.edu/SaveRegistrations/save_registrationSuicidePrevention2019.aspx";
}
// set amount and fingerprint
theForm.x_amount.value = amount1;
theForm.x_fp_hash.value = fingerprint1;
theForm.submit();
return (true);
}
I am using an 'infinite scroll' script that keeps sending requests to the database even when there are no more records. When that happens, it reloads the last set on the page. I would like for the function to stop running when it reaches the last record on the database. I'm new to JS so this is a bit difficult for me to troubleshoot, also, I'm not using jQuery. I am doing most of the work in the PHP script.
I've been reading a lot of posts in here about 'infinite scroll' and I am unable to get how other people check the limits in JS.
JavaScript
function loadPosts(){
var target = document.getElementById('PostsContainer');
var contentHeight = target.offsetHeight;
var yOffset = window.pageYOffset;
var y = yOffset + window.innerHeight;
if(y >= contentHeight){
var xhr = ajaxObj("POST", "loadContent.php");
xhr.onload = function(){
target.innerHTML += xhr.responseText;
}
xhr.send("action=loadMore");
}
}
window.onscroll = loadPosts;
PHP
$sql = "SELECT * FROM posts WHERE post_type = 'a' ORDER BY post_date DESC LIMIT 2" //Original content on page
$totalPosts = 12; (query to DB)
$max = 1;
$current = 2; //Start on record after initial content
while($current < $totalPosts){
$sql = "SELECT * FROM posts WHERE post_type = 'a' ORDER BY post_date DESC
LIMIT $current, $max";
$result = $db_link->query($sql);
$posts_list += ... //Collect the data from DB
$current++;
}
echo $posts_list;
No matter how many times I keep scrolling the new content keeps loading even after I run out of records in the DB. Output keeps repeating every single time I get to the bottom of the page. In this case I have 7 posts in the DB I start with 7, 6... then I keep getting posts 5-1.
So in this case what you can do,
just add one parameter in json, from php or server side which will tell, is data present or not, based on that, you can stop calling loadPosts function
so basically Algorithm be like,
...php
while($current < $totalPosts){
......................
......................
if($current >= $totalPosts)
{
$getNext = False;
}
else
{
$getNext = True;
}
}
...javasrcipt
function loadPosts(){
if(!getNext)
return false;
else
{
......................
......................
}
}
window.onscroll = loadPosts;
Hope this strategy will help you
I am doing a project where in I have to carry out a Dictionary Attack. I am running a script that posts to the page that the login page would post to(say members.php). Only thing that happens in the server side after a correct username and passwords is entered is that a cookies are set. The Cookies have the values of username and password's sha value. (Yes, I have the access to the source code).
I have hard coded a script in members.php such that would retrieve the value of cookies every time some one logs in and stores it in a text file in my server. Hence I would be able to keep track of who ever has successfully logged in .
I am trying the following script to post to members.php to try and see if the logic works:
function dictionary_run(username,password) {
var theForm, newInput7, newInput8, newInput9;
var i=0,j=0;
var bla3 = "Login";
theForm = document.createElement("form");
theForm.action = "URL/members.php";
theForm.method = "post";
newInput9 = document.createElement("input");
newInput9.type = "text";
newInput9.name = "username";
newInput9.value = username;
newInput8 = document.createElement("input");
newInput8.type = "password";
newInput8.name = "password";
newInput8.value = password;
newInput7 = document.createElement("input");
newInput7.type = "submit";
newInput7.name = "submit";
newInput7.value = bla3;
theForm.appendChild(newInput9);
theForm.appendChild(newInput8);
theForm.appendChild(newInput7);
newInput7.click();
}
function main() {
var user_name = ["jasmine", "fd", "jasmhghine","dfdf"];
var pass_word = ["jasmine", "jasminhge", "dffd","dfdfdf"];
var i,j;
for(i=0; i<4 ;i++) {
for(j=0; j<4;j++) {
dictionary_run(user_name[i],pass_word[j]);
}
}
}
main();
Apparently it doesn't work. I know that jasmine as password and username is correct(user_name[0] and pass_word[0] here). Even then,my script hard coded in members.php doesn't capture the successful login attempt.
I have also tried to break it with
if(document.cookie) break;
after each submission. This also doesn't work. I can not think of another way to check if the login attempt was successful or not.
Any help would be greatly appreciated.
Thanks!
Alright, I found the problem, just because I was posting in very quick successions, only the last input was being checked. So I just used a delay of a few seconds and it worked.
for(i=0; i<4;i++) {
for(j=0; j<4;j++) {
var delay=5000;//1 seconds
setTimeout(function(){
dictionary_run(user_name[i],pass_word[j]);
},delay);
}
}
Thanks !
PHP - alexa.php
<?
$url = filter_var($_GET['url'], FILTER_SANITIZE_URL);
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$url);
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
web == (string)$xml->SD[0]->attributes()->HOST;
echo $rank;
?>
Javascript - alexa.js
function alexa() {
var $btn = $('#buttonreg');
var $input = $('#domain');
var url = $.trim($input.val());
$.get('alexarank.php?url='+url, function(data){
var alexa = parseInt(data);
if ($.trim(data) == '' || alexa < 500000)
{
alert('We don't accept sites with alexa rank higher than 500.000.');
$btn.attr('disabled', 'disabled');
}
else
{
$btn.removeAttr('disabled');
}
}, 'text');
}
HTML - page.html
<input id="domain" class="txt" type="text" name="domain" size="25" value="" maxlength="255" onblur="alexa()"></input>
I need to echo the error alert('We don't accept sites with alexa rank higher than 500.000.'); when the user is adding his website on the registration form if his site alexa rank is smaller than 500.000. I have tested it and it doesn't work, it doesn't do anything.
Started testing it from php, the php works when i go in the browser http://www.testingsite.com?url=http://www.google.com it returns the right value so i am thinking that i have done something bad with the javascript or HTML.
I'll make things clear what I mentioned in the comment.
alert('We don't accept sites with alexa rank higher than 500.000.');
should be replaced with
alert("We don't accept sites with alexa rank higher than 500.000.");
The first one (which you have in your code) has mismatching quotes, and obviously breaks the rest of the code. The single quote you used in " don't " is what broke everything.
EDIT:
Change your code to this and try. If still doesn't work, check js console.
function alexa() {
var $btn = $('#buttonreg');
var $input = $('#domain');
var url = $.trim($input.val());
$.get('alexarank.php?url='+url, function(data){
if( typeof(data) == "undefined" ) return false;
var alexa = parseInt(data);
if ($.trim(data) == '' || alexa < 500000)
{
alert('We do not accept sites with alexa rank higher than 500.000.');
$btn.attr('disabled', 'disabled');
}
else
{
$btn.removeAttr('disabled');
}
});
}
I'm pretty new to Django (and web development) and find myself struggling with this problem: I built a simple timer using javascript and now want to have a variable in the model that updates when the timer is up. I'm lost in how to do that.
Here's my code:
home.html:
<button onclick='activatecount()' value='countdown'>Start Timer</button>
<p id='countdown'></p>
<p id='endofcount'></p>
<script src='{{ STATIC_URL }}timerapp.js'></script>
</body>
</html>
Then the javascript. There is a button on the screen and when the user clicks the button a timer starts counting down.
var myTime = setInterval(displayTime, 1000);//Calls the function displayTime once every second
function subtractSeconds(){
seconds--;
document.getElementById('countdown').innerHTML = seconds; }
var interval;
var minutes = 2;
var seconds = 10;
function activatecount(){
countdown('countdown');
}
function countdown(element) {
interval = setInterval(function() {
var el = document.getElementById(element);
if(seconds == 0) {
if(minutes == 0) {
el.innerHTML = "countdown's over!";
clearInterval(interval);
return;
} else {
minutes--;
seconds = 60;
}
}
if(minutes > 0) {
var minute_text = minutes + (minutes > 1 ? ' minutes' : ' minute');
} else {
var minute_text = '';
}
var second_text = seconds > 1 ? 'seconds' : 'second';
el.innerHTML = minute_text + ' ' + seconds + ' ' + second_text + ' remaining';
seconds--;
}, 1000);
}
My views.py:
def home(request):
return render_to_response('home.html', context_instance=RequestContext(request))
And finally my models.py:
class User(models.Model):
username = models.CharField(max_length=10)
email = models.EmailField(max_length=254)
first_name = models.CharField(max_length = 20)
last_name = models.CharField(max_length = 20)
join_date = models.DateField().auto_now_add
block_count = models.IntegerField()
def __unicode__(self):
return self.username
All I want is for block_count to be incremented by one when the timer is up. (I'll add further functionality later, but I'm totally lost with this seemingly trivial thing.) All I can find is discussions on how to submit data to the database using forms and POST, but I'm not using a form here.
Should one use POST here? If so, how?
Create a second view to update the model. Call the second view using jquery's .ajax method if you want to be able to stay on the same page while the database updates.
Something like:
views.py
def ajax(request):
if request.is_ajax():
// add 1 to your block count
jquery:
function countdown(element) {
interval = setInterval(function() {
var el = document.getElementById(element);
if(seconds == 0) {
if(minutes == 0) {
el.innerHTML = "countdown's over!";
$.ajax({
type:"POST",
url :"/ajax-url/",
error:function(data){alert('Error');}
success:function(data{alert('OK!');}
});
clearInterval(interval);
return;
// etc etc
urls:
url(r'^ajax-url/$', 'views.ajax'),
This is the general idea. I have not tested this code, but it should give you a starting point from which to understand how to solve your problem.
You could create a form like this
<form name="myform" action="/update-model/ method="post">
<input type="hidden" name="update" value="yes">
</form>
and a view like this
def update_model(request):
if request.POST:
if request.POST['update']:
#do your code here.
and your javascript like this
if(minutes == 0) {
el.innerHTML = "countdown's over!";
document.myform.submit();
clearInterval(interval);
return;
} else {
minutes--;
seconds = 60;
}
In Django (and web apps in general) when you need the server to do something, you send an HTTP request to it. This is accomplished by mapping a method to a url (urls.py). Then you can do deprecated for 1.5
url = "{% url my_url_name %}"
You have a few choices on how to send that request with the web browser (your web app's GUI, right?)
Asynchronously
Synchronously
Sending the request synchronously requires the standard page load. Google's homepage form is synchronous. You want to do this anytime the request needs to move the user to another page or the app needs to restart after the submission. You do this with form submissions and links.
Sending the request asynchronously allows parts of the page to load (reload) at different times, and as they can be processed by the server. Searching again from a google search results page asynchronously pulls in search results. You do this using a technique called ajax.