20

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.

3
  • Is it possible to give the website you're interested in so that's a little easier to reproduce? Commented Sep 8, 2015 at 15:40
  • I'm actually doing it on an internal test website, so publishing the link won't be possible, sorry :( Commented Sep 8, 2015 at 15:45
  • This may be a wild goose chase, but is it possible that there are two ids that are identical? This has caused me headaches with Selenium before, when it kept trying to act on an id that was under a div and "not visible", while I was trying to get it to click on a different element that had the same id. Commented Oct 4, 2016 at 21:26

2 Answers 2

2

If you're using Chrome browser, right-click on the element you want to "click" in RSelenium, and choose Inspect. Once in the developer console, right-click again on the highlighted element and choose Copy/Copy Xpath. Finally, in your R code use findElement(using="xpath", "xpath string you've copied"). In my experience RSelenium has notoriously issues with finding things on the page using ID, whereas XPath is (again, for me) way more robust.

Sign up to request clarification or add additional context in comments.

Comments

0

I have no idea what driver you're using, but with the chrome driver for PHP you do this:

$javascript = array('script' => 'myfunction();', 'args' => array());
$var = $this->execute($javascript);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.