I have an Rselenium script to fill in a form, but am trying to use CasperJS as I am finding Rselenium too slow. The following code will navigate the form as I expect.
remote.driver$navigate("http://news.ceek.jp/search.cgi?kind=sports")
search.form <- remote.driver$findElement(using = "xpath", "//*[@id='query']")
search.form$sendKeysToElement(list("SearchTerm",key = "enter"))
The equivalent CasperJS code I have tried is the following;
var casper = require("casper").create();
casper.start("http://news.ceek.jp/search.cgi?kind=sports", function() {
this.test.assertExists({
type: 'xpath',
path: '//*[@id="query"]'
}, 'the element exists');
});
casper.then(function() {
this.fill('input[name="q"]', {q:'SearchTerm'}, true);
});
Output from casper;
PASS the element exists
CasperError: Errors encountered while filling form: no field named "q" in form
RSelenium has the advantage that the form parameter does not need to be specified, but presumably casperJS requires this. What should i be using instead?
I am inspecting the elements, but having trouble identifying the form parameter in a such a case. How does one go about this in general?
The first argument to
casper.fill()
is the selector of the form. If you don't have a form surrounding the input element, then you cannot use thecasper.fill*
functions.The workaround would be to use
Also, you should use the XPath helper: