What does arguments[0] and arguments[1] mean when using executeScript method from JavascriptExecutor interface through Selenium WebDriver?

前端 未结 3 1785
闹比i
闹比i 2020-12-06 11:59

What does arguments[0] and arguments[1] mean when using executeScript() method from JavascriptExecutor inter

3条回答
  •  难免孤独
    2020-12-06 12:50

    For executeScript API: executeScript(script/function, arg1, arg2, arg3, ...)

    The first argument is a javascript snippet or a javascript function, if it's a javascript snippet, it will be wrapper into an javascript function inside executeScript.

    The next arguments are the arguments for the javascript function represents the first argument.

    arguments is javascript function build-in feature. you can use it to get real passed-in arguments when call function. Please see below example:

    test('tom', 12, 'male', '175cm') // call function: test
    
    function test(name, age) {
      console.log(name); // tom
      console.log(age);  // 12
      console.log(arguments); // ['tom', 12, 'male', '175cm']
      console.log(arguments[0]); // equal to argument: name, so print tom
      console.log(arguments[1]); // equal to argument: age, so print 12
      console.log(arguments[2]); // male
      console.log(arguments[3]); // 175cm
    }
    

    More detail about Javascript Function.arguments

提交回复
热议问题