I'm trying to automate a process of logging on to a website and performing some process on it, using the RSelenium
package. I have been able to login, click on buttons here and there, but I am stuck at executing a jQuery
function on the page. There's a dropdown box which populates data in it using a jQuery
function. I'm not sure how to execute this function. The page source (including the jQuery
function) is as follows:
<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>
The name of the dropdown is stuff
and I'm using the following code to access it:
library("RSelenium")
startServer()
mybrowser <- remoteDriver()
mybrowser$open()
mybrowser$navigate("<URL>")
wxChooseStuff <- mybrowser$findElement(using='id',"stuff")
when I try to execute the following command:
wxChooseStuff$clickElement()
I get the following error:
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
I was hoping that the click would auto-populate data in the dropdown.
Any pointers on how to execute the jQuery function using RSelenium
would be much appreciated.
Even if I can execute the jQuery
function using another package, that will be fine. I would like to just execute this function and click on the element.
PS - I'm not a web developer, so pardon me if I'm asking a stupid question.
EDIT:
I tried the following code as per suggestion:
In this command, I just include the complete text enclosed in the script
tag, replacing all the double quotes ("
) with single quotes ('
)
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()
but I received the following error:
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
Looks like the element is still not to be found.