Writing JavaScript for automatization - node.click() is not enough - page still think that no radio button is selected

41 views Asked by At

I am writing my userscript for Wikiedia Commons, for this block:enter image description here

I tried

node.click()

node.dispatchEvent(new MouseEvent('click'))

node.dispatchEvent(new MouseEvent('click', {bubbles: true, cancelable: false, view: window}))

And visually the correct radio button is selected, but when pressing Next I am getting error

Selection is required

enter image description here

So, for some reasong, JS click() is not the same as human click?

1

There are 1 answers

0
Vitaly Zdanevich On

Solved by clicking to another element:

const knowledge = document.querySelector('[value="knowledge"]')
if (knowledge && knowledge.checked == false) {
    knowledge.parentNode.nextSibling.click()
}