AutoClick on Submit Button Javascript - javascript

This is whole code for this button <button type="submit" tabindex="46" class="btn-2 floatRight" onclick="_gaq.push(['_trackEvent', 'Rejestracja', 'Rejestracja - koszyk']);">Next</button>
I tried to put this _gaq.push(['_trackEvent', 'Rejestracja', 'Rejestracja - koszyk']); in GreaseMonkey to automatically proceed next step, but with no result.
Thanks for any ideas!
Have a nice day!

You're doing it wrong, you should instead find the button using document.querySelector() and then click it using the click() function, like this:
document.querySelector("button.btn-2").click()

Related

Click button in webpage with Javascript

Currently, I'm doing an application and I need login to this one particular website. Basically, I need to make this button click using a javascript but I have no idea how to.
This is the button code I retrieved from the website:
<button type="submit" class="uk-width-1-1 uk-button uk-button-primary uk-button-large">Sign in</button>
Thank you for your help in advance
You can click on the button programmatically, in case of pure javascript :
(function(){document.querySelector('button[type="submit"]').click();})()
In case of Android JS Interface :
webView.loadUrl("javascript:(function(){"+
"l=document.querySelector('button[type=\"submit\"]');"+
"e=document.createEvent('HTMLEvents');"+
"e.initEvent('click',true,true);"+
"l.dispatchEvent(e);"+
"})()");
The general way to have button click events is to use something like jQuery. For example lets set the button to have an ID
<button id="my-button" type="submit" class="uk-width-1-1 uk-button uk-button primary uk-button-large">Sign in</button>
Then we would apply a click event to it with jQuery
$('#my-button').click(function(){alert('button has been clicked');})
Instead of the alert you could put whatever code you want in there :D
Example: Codepen example
EDIT: Example for a class:
Example for a class
(Note that we use a "." instead of "#" in the call)
-Kyle

Unable to click on the submit button with xpath and classname using selenium webdriver

This is the html code :
...
<div class="span_3_of_4">
<p class="text_popup"> Dont Have an Account? |
<a class="fancybox" href="#load_box">Signup</a>
</p>
</div>
<div class="span_1_of_4" align="center">
<input class="button" type="submit" value="Submit"/>
</div>
</div>
</form>
</div>
<script src="js/jquery.form.js" type="text/javascript"/>
Its a submit button. I am trying to automate a registration for using selenium webdriver. There are no ids or names as such for this button. Hence i tried with xpath (taken from firebug) .//*[#id='load_form']/div/div[2]/input and classname - button.
Yet the following error was being thrown Element is not currently visible and so may not be interacted withCommand duration or timeout: 428 milliseconds.
Please suggest as to how can i ever overcome this error and be able to click on the "submit" button.
Selenium Version - 2.44
I encounter this issue a lot, and one thing that normally solves the problem is switching frames. With python I think it's something like driver.switch_to_frame('frame') I may be wrong there with the syntax but definitely try that out
Try this one:
driver.findElement(By.xpath("//div[#id='load_box']/form[#id='load_form']//input[#class='button' and #type='submit']"))
Problem was that there are several form elements with "load_form" on the site and the first one is hidden! that's why you need a more specific xpath like the one above.

When I use input type="button" a function works well but when I use button it doesn`t

I call the same function with those two types of button. With the first it works perfectly but with button it works well at the first but in less than one second it looks like refresh the page.
<input type="button" id="bProv" value="filtrar" onclick="filtroP()"/>
<button id="bProv" onclick="filtroP()">filtrar</button>
The type of a <button> element defaults to submit, so it will run the JS and then immediately submit the form.
Use <button type="button" ... if you don't want form submission.
That said, hard coding a button (which does nothing without JS) goes against the principles of unobtrusive JavaScript (which are part of best practise programming for the WWW).

javascript issue in jsf/icefaces

jsf command button doesn't invoking javascript , please suggestions
<ice:commandButton id="submit" onclick="validationmessage();" value="Submit"
Check page source. Does validationmessage() function exist in it?
Check if onclick works. Put something like "alert('blabla')" there. Does it work?

How to make a button redirect to another page using jQuery or just Javascript

I am making a prototype and I want the search button to link to a sample search results page.
How do I make a button redirect to another page when it is clicked using jQuery or plain JS.
is this what you mean?
$('button selector').click(function(){
window.location.href='the_link_to_go_to.html';
})
$('#someButton').click(function() {
window.location.href = '/some/new/page';
return false;
});
Without script:
<form action="where-you-want-to-go"><input type="submit"></form>
Better yet, since you are just going somewhere, present the user with the standard interface for "just going somewhere":
ta da
Although, the context sounds like "Simulate a normal search where the user submits a form", in which case the first option is the way to go.
In your html, you can add data attribute to your button:
<button type="submit" class="mybtn" data-target="/search.html">Search</button>
Then you can use jQuery to change the url:
$('.mybtn').on('click', function(event) {
event.preventDefault();
var url = $(this).data('target');
location.replace(url);
});
Hope this helps
With simple Javascript:
<input type="button" onclick="window.location = 'path-here';">
You can use:
location.href = "newpage.html"
in the button's onclick event.
No need for javascript, just wrap it in a link
<button type="button">button</button>
This should work ..
$('#buttonID').click(function(){ window.location = 'new url'});
You can use window.location
window.location="/newpage.php";
Or you can just make the form that the search button is in have a action of the page you want.
this is the FASTEST (most readable, least complicated) way to do it, Owens works but it's not legal HTML, technically this answer is not jQuery (but since jQuery is a pre-prepared pseudocode - reinterpreted on the client platform as native JavaScript - there really is no such thing as jQuery anyway)
<button onclick="window.location.href='http://www.google.com';">Google</button>
You can use this simple JavaScript code to make search button to link to a sample search results page. Here I have redirected to '/search' of my home page, If you want to search from Google search engine, You can use "https://www.google.com/search" in form action.
<form action="/search"> Enter your search text:
<input type="text" id="searchtext" name="q">
<input onclick="myFunction()" type="submit" value="Search It" />
</form>
<script> function myFunction()
{
var search = document.getElementById("searchtext").value;
window.location = '/search?q='+search;
}
</script>
From YT 2012 code.
<button href="/signin" onclick=";window.location.href=this.getAttribute('href');return false;">Sign In</button>
Use a link and style it like a button:
Click this button
And in Rails 3 with CoffeeScript using unobtrusive JavaScript (UJS):
Add to assets/javascripts/my_controller.js.coffee:
$ ->
$('#field_name').click ->
window.location.href = 'new_url'
which reads: when the document.ready event has fired, add an onclick event to a DOM object whose ID is field_name which executes the javascript window.location.href='new_url';
There are a lot of questions here about client side redirect, and I can't spout off on most of them…this one is an exception.
Redirection is not supposed to come from the client…it is supposed to come from the server. If you have no control over the server, you can certainly use Javascript to choose another URL to go to, but…that is not redirection. Redirection is done with 300 status codes at the server, or by plying the META tag in HTML.

Categories

Resources