使用RSelenium包执行jQuery函数

前端之家收集整理的这篇文章主要介绍了使用RSelenium包执行jQuery函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用RSelenium包自动登录网站并执行一些过程.我已经能够登录,点击这里和那里的按钮,但我被困在页面上执行一个jQuery功能.有一个下拉框,使用jQuery函数填充数据.我不知道如何执行这个功能.页面源(包括jQuery函数)如下:
<input disabled="disabled" id="stuff" name="stuff" style="width:100%" type="text" /><script>
    jQuery(function(){jQuery("#stuff").kendoDropDownList({"change":disableNext,"dataSource":{"transport":{"read":{"url":"/StuffInfo/GetStuff","data":filterStuff},"prefix":""},"serverFiltering":true,"filter":[],"schema":{"errors":"Errors"}},"autoBind":false,"optionLabel":"Select court...","cascadeFrom":"state"});});
</script>
            <script>

下拉菜单名称是东西,我正在使用以下代码来访问它:

library("RSelenium")

startServer()
mybrowser <- remoteDriver()
mybrowser$open()
mybrowser$navigate("<URL>")
wxChooseStuff <- mybrowser$findElement(using='id',"stuff")

当我尝试执行以下命令:

wxChooseStuff$clickElement()

我收到以下错误

Error:   Summary: ElementNotVisible
     Detail: An element command could not be completed because the element is not visible on the page.
     class: org.openqa.selenium.ElementNotVisibleException

我希望点击会自动填充下拉列表中的数据.

任何关于如何使用RSelenium执行jQuery函数的指针都将不胜感激.

即使我可以使用另一个包执行jQuery函数,这样就可以了.我想执行这个功能并点击元素.

PS – 我不是一个网页开发者,所以请原谅我,如果我问一个愚蠢的问题.

编辑:

我按照建议尝试了以下代码

在这个命令中,我将包含在脚本标签中的完整文本,将所有双引号(“)替换为单引号(‘)

mybrowser$executeScript(script = "jQuery(function(){jQuery('#stuff').kendoDropDownList({'change':disableNext,'dataSource':{'transport':{'read':{'url':'/StuffInfo/GetStuff','data':filterStuff},'prefix':''},'serverFiltering':true,'filter':[],'schema':{'errors':'Errors'}},'autoBind':false,'optionLabel':'Select court...','cascadeFrom':'state'});});")

wxChooseStuff <- mybrowser$findElement(using='id',"stuff")
mybrowser$executeScript(script = "arguments[0].hidden = false;",args = list(wxChooseStuff))
wxChooseStuff$clickElement()

但是我收到以下错误

Error:   Summary: ElementNotVisible
     Detail: An element command could not be completed because the element is not visible on the page.
     class: org.openqa.selenium.ElementNotVisibleException

看起来元素还没有被找到.

解决方法

我不知道你使用什么驱动程序,但是使用chrome驱动程序,您可以执行以下操作:
$javascript = array('script' => 'myfunction();','args' => array());
$var = $this->execute($javascript);

猜你在找的jQuery相关文章