简体   繁体   English

如何在浏览器控制台中运行 JavaScript function?

[英]How to run JavaScript function in browser console?

In my Python program, I need to run the hcaptchaCallback function (screenshot), but the function name has a different numbers each time.在我的 Python 程序中,我需要运行 hcaptchaCallback function(截图),但 function 名称每次都有不同的数字。 Can I somehow run this function by specifying only the first part of the name (hcaptchaCallback)?我可以通过仅指定名称的第一部分 (hcaptchaCallback) 以某种方式运行此 function 吗?

driver.execute_script('hcaptchaCallback...()')

在此处输入图像描述

There is nothing that lets you really do that.没有什么能让你真正做到这一点。 You might be able to pull off looping over the globals and looking for a variable that starts with your string.您可能能够结束对全局变量的循环并查找以您的字符串开头的变量。

window[Object.keys(window).find(k=>k.startsWith("hcaptchaCallback"))]();

that will call it the way you showed, but looking at the function signature, looks like you are going to have to use call()这将按照您显示的方式调用它,但查看 function 签名,看起来您将不得不使用call()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 chrome-从浏览器控制台“未定义”运行javascript函数 - chrome - run javascript function from browser console “undefined” 如何在浏览器控制台的匿名函数中使用javascript函数? - How to work with javascript functions in an anonymous function in the browser console? 如何从浏览器控制台访问存储在函数闭包中的javascript变量? - How to access javascript variable stored in function closure from browser console? 如何从浏览器控制台禁用 JavaScript 函数调用? - How to disable JavaScript function calls from the browser console? 如何在不执行该功能的情况下在Web浏览器中运行javascript函数 - How to run javascript function in web browser only when is not proccesing that function 如何在浏览器上运行JavaScript? - How to run a javascript on a browser? Javascript Function 与在 web 浏览器中通过控制台运行相比,调用具有不同的行为 - Javascript Function Call have different behaviour compared to run by console in web browser Java Selenium,如何直接定义/修改javascript函数并在浏览器中运行它? - Java Selenium, how to directly define/modify javascript function and run it in browser? 如何为JavaScript运行Windows控制台 - How run a windows console for JavaScript 使用 Visual Studio 2019 时如何在浏览器而不是控制台中运行 Javascript 程序 - How to run Javascript program in browser instead of console when using Visual Studio 2019
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM