'how to run javascript function in selenuim
how i can run this js code in selenuim
window.hcaptcha.render = (container, params) => {
console.log(container)
console.log(params)
window.hcaptchaCallback = params.callback
}
const scriptUrl = new URL(Array.from(document.querySelectorAll('script')).filter(s => s.src.includes('https://js.hcaptcha.com/1/api.js')).map(s => s.src)[0])
window[scriptUrl.searchParams.get('onload')]()
I tried whith driver.execute_script but it doesn't work
driver.execute_script('window.hcaptcha.render = (container, params) => { window.hcaptchaCallback = params.callback }')
driver.execute_script("const scriptUrl = new URL(Array.from(document.querySelectorAll('script')).filter(s => s.src.includes('https://hcaptcha.com/1/api.js')).map(s => s.src)[0])")
driver.execute_script("window[scriptUrl.searchParams.get('onload')]();")
Solution 1:[1]
You can use python multi-line strings with triple quotes e.g """ .... """
or ''' ... '''
driver.execute_script("""
window.hcaptcha.render = (container, params) => {
console.log(container)
console.log(params)
window.hcaptchaCallback = params.callback
}
const scriptUrl = new URL(Array.from(document.querySelectorAll('script')).filter(s => s.src.includes('https://js.hcaptcha.com/1/api.js')).map(s => s.src)[0])
window[scriptUrl.searchParams.get('onload')]()
""")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Water Man |