当通过Selenium WebDriver从JavascriptExecutor接口使用executeScript方法时,参数[0]和参数[1]是什么意思? [英] What does arguments[0] and arguments[1] mean when using executeScript method from JavascriptExecutor interface through Selenium WebDriver?

查看:1554
本文介绍了当通过Selenium WebDriver从JavascriptExecutor接口使用executeScript方法时,参数[0]和参数[1]是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 <$ c $时, arguments [0] arguments [1] 是什么意思c>来自 JavascriptExecutor 接口的executeScript() 方法通过Selenium WebDriver,参数的目的是什么[0] 在下面的代码中。

What does arguments[0] and arguments[1] mean when using executeScript() method from JavascriptExecutor interface through Selenium WebDriver and what is the purpose of the arguments[0] in the below code.

javaScriptExecutor.executeScript("arguments[0].click()", webElement);


推荐答案

方法nofollow noreferrer> JavascriptExecutor 接口可以以 arguments [0] arguments [1] 的形式调用多个参数,等等

The executeScript() method from the JavascriptExecutor Interface can invoke multiple arguments in the form of arguments[0], arguments[1], etc


  • 根据你的例子,到 javaScriptExecutor.executeScript(arguments [0] .click( ),webElement); 工作需要定义 webElement executeScript()方法将元素的引用作为 arguments [0] 以及 <要执行的em>方法 [在这种情况下 click()],之后应该提供引用。

  • As per your example, to javaScriptExecutor.executeScript("arguments[0].click()", webElement); to work you need to have the webElement defined. executeScript() method will take the reference of the element as arguments[0] along with the method to be performed [in this case click()] and the reference should be provided thereafter.

WebElement webElement = driver.findElement(By.xpath("xpath_element"));
JavascriptExecutor javaScriptExecutor = (JavascriptExecutor)driver;
javaScriptExecutor.executeScript("arguments[0].click()", webElement);


  • 同样, executeScript()的示例参数[] 的$ c>如下:

  • Similarly, an example of executeScript() with multiple arguments[] is as follows :

    JavascriptExecutor js = (JavascriptExecutor) driver; 
    js.executeScript("arguments[0].setAttribute('style', arguments[1])", driver.findElement(By.xpath("//input[@type='file']")), "0");
    

    此示例中为:


    • driver.findElement(By.xpath(// input [@ type ='file'] 被称为 arguments [0]

    • 0被称为参数[1]

    • driver.findElement(By.xpath("//input[@type='file'] is referred as arguments[0]
    • "0" is referred as arguments[1]

    这篇关于当通过Selenium WebDriver从JavascriptExecutor接口使用executeScript方法时,参数[0]和参数[1]是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆