使用RSelenium包执行jQuery函数
我正在尝试使用使用RSelenium包执行jQuery函数,jquery,r,rselenium,Jquery,R,Rselenium,我正在尝试使用RSelenium软件包自动化登录网站并在其上执行某些过程。我已经能够登录,点击这里和那里的按钮,但是我在执行页面上的jQuery功能时遇到了麻烦。有一个下拉框,它使用jQuery函数填充其中的数据。我不知道如何执行这个函数。页面来源(包括jQuery函数)如下所示: <input disabled="disabled" id="stuff" name="stuff" style="width:100%" type="text" /><script>
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>
当我尝试执行以下命令时:
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
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-我不是网络开发者,所以如果我问了一个愚蠢的问题,请原谅
编辑:
根据建议,我尝试了以下代码:
在这个命令中,我只包含包含在脚本
标记中的完整文本,将所有双引号(“
)替换为单引号(”
)
看起来仍然找不到元素。我不知道您使用的是什么驱动程序,但使用chrome PHP驱动程序,您可以执行以下操作:
$javascript = array('script' => 'myfunction();', 'args' => array());
$var = $this->execute($javascript);
如果您使用的是Chrome浏览器,右键单击要在RSelenium中“单击”的元素,然后选择
Inspect
。在开发人员控制台中,再次右键单击突出显示的元素,然后选择Copy/Copy Xpath
。最后,在R代码中使用findElement(使用=“Xpath”,“您复制的Xpath字符串”)
。根据我的经验,RSelenium在使用ID查找页面上的内容时出了名的问题,而XPath(同样,对我来说)是更强大。是否可以提供您感兴趣的网站,以便更容易复制?我实际上是在一个内部测试网站上进行的,因此无法发布链接,抱歉:(这可能是白费力气,但有可能有两个id是相同的吗?这让我以前对Selenium感到头疼,当时它一直试图对一个位于div下且“不可见”的id进行操作,而我试图让它单击具有相同id的不同元素。
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
$javascript = array('script' => 'myfunction();', 'args' => array());
$var = $this->execute($javascript);