Simulating Clicking a span/div element, not working - javascript

I'm trying to make an automation tool for google classrooms to auto-submit my work for me, instead of having to go through 1-by-1 (I have more than 100 to be turned in), and I'm trying to make js press the submit work/mark as done button. I've tried with all the divs and spans, but it doesn't do anything. here's some screen shots:
the code:
var elementsArray = document.getElementsByClassName("uArJ5e TuHiFd UQuaGc Y5sE8d M9Bg4d");
alert(elementsArray[0].innerHTML);
var span = elementsArray[0];
var click = new Event('click');
span.dispatchEvent(click);
Trying to run the script makes the alert pop up, but nothing else happens. No errors appear in the console, and I'm wondering why this isn't working. Any answers would be nice, thanks.

maybe you can try span.click()

Can you try with elementsArray[0][2] instead of elementsArray[0]?

Related

Clicking a button with a chrome extension (ERROR/Not working)

Hello I want to click a button multiple times when on a specific website. I have no idea whats wrong but maybe someone can help me out
function pay(){
document.getElementsByClassName("btn btn--lg btn--full u-margin-b--xl js-place-order2 js-place-order-btn")[0].click();
}
if(window.location.href.includes("https://www.revolveclothing.fr/r/ReviewConfirm.jsp?enteraccount")){
var sleep = setTimeout(pay, 50)
}
The element I am Clicking is the correct one since it works in the chrome console
I hope someone can help me
Since you're using setTimeout, the button will only be pressed once after 50ms is elapsed.
Assuming you want it to be pressed consistently every 50ms, you should change the setTimeout to setInterval like so:
var sleep = setInterval(pay, 50);

How can I make a function to program Chrome to set itself the "Break" status at my workplace

I am working in a call center, and everytime i go to the toilet, I have to change my status to "Break" using a dropdown menu from the google chrome page(internal website).
I can use inspect and see all the classes and button ids but for some reasons it's not working, it give me the error "undefined".
function Myfunc (){
var button1 = document.getElementById("_10erop07");
button1.click();
}
How Can i make a script, that at a certain hour, I enter code here will automatically trigger at the certain hour.
Basically, I want the script to click on the dropdown and select the "Break" status.
Any ideas how can I do that?
This can easily be done using Bookmarklets
follow the steps in the guide link above.
your javascript code should look something like this
javascript:(
function(){
// YOUR CODE SHOULD BE HERE
}
)();
But make sure to click the bookmarklet when you are in the website
I hope that helps.

Create an confirm box for external links to a certain class, maybe with document.getElementByCLassName?

I'm new to JavaScript and want a function that activates when you click on a link that leads outside the website. It should alert that you are about to leave the page and bring up a box that says "Do you really want to leave the site?" with response alternatives "OK" and "Cancel".
I've managed to do this like this (with an img that works like a link):
HTML:
<a href="http://www.urbanoutfitters.com"
onClick="return confirm('Do you really want to leave the site?')"
class="relaterade"> <img src="img5.jpg"/> </a>
I wonder if you can make a function so all in the class "relaterade" gets this confirm box instead of writing this on every single link. Maybe with document.getElementByCLassName? I want all JavaScript in a separate document.
Thanks! :)
You can get the element collection by doing document.getElementsByClassName. You must then loop through the collection and set the onclick event handler
var elements = document.getElementsByClassName('yourclass');
for (var element in elements) {
elements[element].onclick = function() {
return confirm('are you sure?');
}
}
this is from the top of my head, so dont know if it works for sure.
You could do this more easily with a library like jQuery though, cause IE < 9.0 will fail on the getElementsByClassName function

Make browser's back button work when using hide and show (jquery)

I've seen the new website of megaupload (mega) and we've got this:
Ok, if I press on left-menu contacts, it only reloads the white part on the image, if I press messages, the same, it only reloads white part. But if I go from contacts to messages and I press browser's back button, it goes from messages to contact and only reloads white part as always.
In my website, I do the same using jquery hide and show, but obviously, if I press browser's back button it doesn't hide the div and shows the other one.
My web site is only one html file and there are 4 div that get shown or hidden depending on the button you press, this is an example:
$("#btn_contact").click(function () {
$("#content_contact").show();
$("#content_home").hide();
$("#content_products").hide();
$("#body_aux").hide() ;
$(this).addClass('visited');
$('#btn_products').removeClass('visited');
$('#btn_home').removeClass('visited');
});
Can anybody tell me how to find this with jquery or whatever I have to use.
I don't know if I've explained myself well, if not, ask me to do it better.
I would appreciate any help. Thanxs a lot.
Maybe it'd be easier for you and more appropiate to make "content_contact.html", "content_home.html", and so on and use .load() function as Ozan Deniz said. You wouldn't have to change margins, positions, etc. and back button would work withouth programming. I think is not appropiate to make the whole website using just one html file, showing and hiding div's, ofcourse you can do this but maybe is not the right way. I'm newbie at this, but that's what an expert told me beacuse I was doing something similar to that.
Hope to help you.
You can use jquery load function to load white part
For example;
$('#result').load('ajax/test.html');
And in back button event you can load the white part
jquery hide and show
window.onbeforeunload = function() { $('#result').hide(); }; or
window.onbeforeunload = function() { $('#result').show(); };
jquery load function
window.onbeforeunload = function() { $('#result').load('ajax/test.html'); };

Alert Box error

I have alert boxes all around my site, that have been working up until now, ( I have done a few updates to my blog recently before this started happening ) the problem I am experienceing is that when I click on a link ( in my case a image link ) and the alert box appears, I submitt the ok button and suddenly im rediercted to a white page with 'true' in the top corner. My alert box scripts are inside my blog template.
I tested this alert box script out in a blog post:
<"a href="javascript:onClick=alert("Not an active link");">CLICK<"/a>
withouth the extra "
and then went to preview the post, however the same error occured. This is not a browser problem as it only happens on my site, when i got to someone elses with alert boxes, it works. Please help with this I have been asking about it for about a week now and would appreciate someone who can help
here is a screenshot of what I get redirected to:
http://img813.imageshack.us/img813/2674/true.png
Thanks for all help.
Use this
CLICK
Demo here: http://jsfiddle.net/e2fkT/embedded/result/
I think you have some typos... It would be:
click
Use simple quotes inside or escape double quotes.
I don't understand the use of onclick there too... Just the alert will open an alert box when you click.
click
Also it would be better to separate javascript from html... You could include with the following content (jquery example, i forgot almost everything about old javascript... just get the idea) into a non-active-links.js file or in a block:
$(document).ready(function () {
$('a.non-active-link').click(function () {
window.alert('Not an active link');
return false;
});
});
That way all links in the page with a class attribute of "non-active-link" will fire up the alert box.
I think you messed up with javascript inside href and the onclick attribute. Your snippet is actually assigning the result of the alert function call to the variable onCLick. The display of true might be the return value of the alert method. Still an odd behavior.
CLICK
CLICK
Those two cause no problems to me.

Categories

Resources