If you check the value of your singleNodeValue
, you will notice it is null. This is because your XPath is wrong.
The correct full XPath is: /html/body/div[2]/div[4]/div[2]/form/fieldset/p[4]/input
However, this path is very likely to break in the future, because it relies on the <div>
s and <p>
s to be located in specific positions. You can make a more "relaxed" XPath which will still find the right element. In fact, you can easily do this in Google Chrome by right clicking the button, click Inspect, and then right click the DOM element and choose Copy Xpath.
The resulting code would be:
document.evaluate('//*[@id="tool-submit-button"]/input', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();
If you want to use it on page load, you should first check if the video has already been converted. You may also need to wait for the button to load:
var checkTimer = setInterval(function() {
var button = document.evaluate('//*[@id="tool-submit-button"]/input', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (button) {
clearInterval(checkTimer);
// Only convert if the gif hasn't already been converted
if (!document.getElementsByTagName("video")[0])
button.click();
}
}, 50);