Trigger click not working

╄→尐↘猪︶ㄣ 提交于 2019-12-13 10:27:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!