Selenium Webdriver Node.js:如何加载和执行jQuery代码

我使用Selenium webdriver&Node.JS进行functiontesting。

我试图使用jQuery代码做一些处理。

  1. 首先,我试图包括jquery并加载它:

    driver.executeScript(“var s = window.document.createElement('script'); \ s.src =' https: //cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js '; \ window.document.head.appendChild(s);“);

– > 这个治疗似乎被执行(因为我没有捕捉到相关的错误)

  1. 但是,当试图使用jQuery的function,这里是一个例子:

    driver.executeScript( “$( '#编辑提交')上( '点击',函数(){警报( 'testing');})”);

    我正在抓住这个:

我的error handling程序… WebDriverError:未知错误:$不是一个函数

似乎jquery要么没有成功加载,或者我没有正确使用它。

build议?