He estado buscando en Google y leyendo MDN, y probando diferentes cosas, y todavía no puedo hacer que funcione. ¿Alguien puede ayudar con esto? ¿Por qué causa tal problema?
js = ''' var xhr = new XMLHttpRequest(); xhr.open('POST', 'https://www.ti.com.cn/occservices/v2/ti/addtocart', false); xhr.setRequestHeader('Content-type', 'application/json'); xhr.send('{"cartRequestList":[{"packageOption":null,"opnId":"%s","quantity":"%d","tiAddtoCartSource":"store-pdp","dienCode":"","year":"","week":"","batchCode":"","pcrCode":"","sparam":""}],"currency":"CNY"}'); return xhr.response;''' % (product['opn'], product['num']) js = js.replace(" ", "").replace("\n", "") resp = driver.execute_script(js) return resp