我正在尝试使用该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>
下拉列表的名称是stuff
,我正在使用以下代码来访问它:
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
我希望点击会自动填充下拉列表中的数据。
任何有关如何使用执行 jQuery 函数的指针RSelenium
将不胜感激。
即使我可以jQuery
使用另一个包执行该功能,也可以。我只想执行此功能并单击元素。
PS - 我不是网络开发人员,如果我问的是一个愚蠢的问题,请原谅我。
编辑:
我按照建议尝试了以下代码:
在此命令中,我只包含script
标记中包含的完整文本,将所有双引号 ( "
) 替换为单引号 ( '
)
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
看起来仍然找不到该元素。