I want to create a macros for automated filling the test questions here https://mooc2-ans.chaoxing.com/, I need to click the "Create new test" button.
i do: Activate Safari -> execute JavaScript in Safari {document.getElementsByClass('jb_btn jb_btn_104 fl fs14').click();}
this how the button looks like: a href="javascript:;" onclick="creatWork();" class="jb_btn jb_btn_104 fl fs14">i class="PlusIcon"新建作业</a
And I works for "yandex.ru" but not here, I'm not familiar with JavaScript, if you know how to solve this problem, please help.
Hi Chris, that's true cuz it requires registration, but I can copy and send all the necessary code for you. My question is how to click the button in safari apple events with JavaScript. I'm trying to do -> getElementByClass but but somehow it doesn't work. Is there any other option?
I have tried:
document.querySelector("div.bnt_group a[onclick='creatWork();']").click();
document.querySelector("div.bnt_group a[href='javascript\:;']").click();
document.querySelector("div.bnt_group a[href='javascript:;']").click();
document.querySelector(".jb_btn.jb_btn_104.fl.fs14").click();
document.querySelector('.jb_btn.jb_btn_104.fl.fs14' a[onclick='creatWork();']).click();
and honestly lots more, it works fine with another website, both and querySelector and getElementByClass, and ignores me here.
it's <a class=''jb_btn jb_btn_104 fl fs14"...> here, with spaces. Other sites I try class doesn't contain spaces. So i put . instead of spaces but fail.
var btnElem = document.querySelector('div.fanyaTask div.bnt_group a.jb_btn');
btnElem.click()
based on an OCR of your HTML image, which could contain errors.
If this does not work, please post a broader range of HTML from your web page using Code Block.
Make sure the HTML contains enough UI elements so we can test run/view in a browser.
[Error] TypeError: null is not an object (evaluating 'ev.click')
Глобальный код (Элемент скрипта 5:10)
[Error] TypeError: null is not an object (evaluating 'btnElem.click')
Глобальный код (Элемент скрипта 6:10)
I don't know what script you are using that causes that error, but when I try the JavaScript I gave you above, it works in the full script that you provided.
I did make some changes to the text display on this web page so I could clearly see which link was being clicked. I also replaced some Chinese text with English.
If I change to a querySelectorAll() it will find all occurrences of that element:
var btnElemCol = document.querySelectorAll('div.fanyaTask div.bnt_group a.jb_btn');
//--- Click on First Link ---
if (btnElemCol) {
var linkFound = 'First Link was found';
btnElemCol[0].click()
} else { var linkFound = 'First Link was found'; }
linkFound;
I have no idea what exactly i do wrong, i am far from programming, but i am able to follow the instruction. Yet, i can do this action for another website but unable to do it for this one, what can go wrong? iGCSE.webarchive.zip (442.8 KB)
I attach webArchive
of course I first tried your script.Запись экрана 2021-03-29 в 08.39.04.zip (5.3 MB)
Add a video, I run the script, but still nothing.
I have a question, can I execute a function instead of clicking the instance?
If you ran my Macro as is, without any changes, and it does not work for you, then I have nothing else to offer. Maybe the language is interfering with our communications and/or the actual script.