简体   繁体   English

JavascriptExecutor如何在selenium webdriver中运行

[英]How does JavascriptExecutor works in selenium webdriver

When somebody inserts some javascript in a webpage using selenium's JavascriptExecutor object and executes it, where does this javascript code go and how does it run? 当有人使用selenium的JavascriptExecutor对象在网页中插入一些javascript并执行它时,这个javascript代码在哪里运行?它是如何运行的?

I mean does it sit in the page forever(until the page is reloaded) or it is executed from outside. 我的意思是它永远位于页面中(直到重新加载页面)或从外部执行。 And if it sits in the page, is it possible to use that code again? 如果它位于页面中,是否可以再次使用该代码?

Also, what if some other javascript code is already running in the page then what happens, does inserted code waits for other js code to stop or is executed parallely from outside the browser. 此外,如果其他一些javascript代码已经在页面中运行,那么会发生什么,插入的代码等待其他js代码停止或从浏览器外部并行执行。

I asked this question because I am working on selenium and using the JavaScriptExecutor . 我问了这个问题,因为我正在研究selenium并使用JavaScriptExecutor So I just wanted to know how internally it works. 所以我只是想知道它的内部工作原理。

After looking into all the API and documentation of JavascriptExecutor this is what I have found. 在查看了JavascriptExecutor所有API和文档之后,这就是我所发现的。

It has two methods namely executeScript and executeAsyncScript . 它有两个方法,即executeScriptexecuteAsyncScript The first methods is synschrous, so if any other already running on the page then possibly the injected script waits for that script to finish. 第一种方法是同步的,因此如果页面上已经运行了任何其他方法,那么注入的脚本可能会等待该脚本完成。

The other method executes any async script(like ajax call or settimeout functions) so the injected script does not has to wait. 另一种方法执行任何异步脚本(如ajax调用或settimeout函数),因此注入的脚本不必等待。

Also the inserted script is executed as a body of an anonymous function. 插入的脚本也作为匿名函数的主体执行。 The local variables dimish after script is finished, but global variable do stay in the page and possibly can be reused after the script finishes. 脚本完成后局部变量会变暗,但全局变量会保留在页面中,并且可能在脚本完成后重用。

If some has more information on this, please provide. 如果有人有更多相关信息,请提供。 Thank you. 谢谢。

暂无
暂无

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

相关问题 如何不使用javascriptExecutor在Selenium Webdriver中突出显示Webelement - How to highlight webelement in selenium webdriver not using javascriptExecutor JavascriptExecutor Selenium WebDriver - JavascriptExecutor Selenium WebDriver Selenium WebDriver(Java):JavascriptExecutor无法单击元素,而WebElement.click()可以正常工作 - Selenium WebDriver(Java) : JavascriptExecutor fails to click element, while WebElement.click() works well C#Selenium Webdriver JavaScriptExecutor提示窗口 - C# Selenium Webdriver JavaScriptExecutor Prompt Window Selenium Webdriver:JavascriptExecutor推动视频播放 - Selenium Webdriver: JavascriptExecutor to push play on video 当通过 Selenium WebDriver 使用来自 JavascriptExecutor 接口的 executeScript 方法时,arguments[0] 和 arguments[1] 是什么意思? - What does arguments[0] and arguments[1] mean when using executeScript method from JavascriptExecutor interface through Selenium WebDriver? 如何使用 Selenium WebDriver 中的 JavaScriptExecutor 在加载 js 脚本时执行 js function - how to execute js function on load of a js script using JavaScriptExecutor in Selenium WebDriver Selenium Webdriver实例上的JavascriptExecutor在导航到其他页面时引发异常 - JavascriptExecutor on Selenium Webdriver instance throwing exception on navigating to other page JavascriptExecutor(Selenium WebDriver C#)不断返回空对象 - JavascriptExecutor (Selenium WebDriver C#) keeps returning null objects 如何在Selenium JavascriptExecutor中执行脚本 - How can script be executed in Selenium JavascriptExecutor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM