问题
Edit: Thank you so much for all the effort, got all my code running now!
I want to trigger a click on https://shop.adidas.ae/en/stan-smith-shoes/S82255.html (to make a shoe bot). Why does this code not work to trigger the size type button?
setTimeout(function () {
$('select.product-type.js-size-type').trigger('click');
}, 1000);
This is the select button:
<select class="product-type js-size-type">
This is what chrome console says
caught TypeError: Cannot read property 'click' of null
at <anonymous>:2:41
Updated:
My manifest of the chrome extension:
{
"name": "name",
"description": "test",
"version": "1.0",
"manifest_version": 2,
"permissions": ["*://*/*"],
"content_scripts": [
{
"matches": ["*://*.adidas.ae/*"],
"js": ["jquery.js", "yeezyCopper.js"]
}
],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
YeezyCopper.js :
setTimeout(function () {
$('select.product-type.js-size-type').trigger('click');
}, 1000);
Thanks in advance!
回答1:
The code works properly, but the "click" event triggered programmatically will not open the select
option list.
See Is it possible to use JS to open an HTML select to show its option list?
You can test that it works by adding your own onclick
event for that element and then triggering the click
event.
回答2:
Update
setTimeout(function () {
$('select.product-type.js-size-type').trigger('click');
}, 1000);
with
setTimeout(function () {
$('select .product-type.js-size-type').trigger('click');
}, 1000);
来源:https://stackoverflow.com/questions/42368802/trigger-click-not-working