Trying to detect and populate a form with RSelenium - r

I have an embedded form on a website I own that I'd like to populate and send using RSelenium.
I can't seem to to detect the elements as a first step. Obviously I'd like then to populate and send.
The form code is:
<div id="form">
<form accept-charset="utf-8" method="POST" novalidate="">
<div class="form-group"><label for="form_Name" class="control-label">Full name<sup>*</sup></label><input required="" pattern="^***+(.****" class="form-control" title="Full name" id="form_Name" type="text" name="form_Name"></div>
<div class="form-group"><label for="form_Email" class="control-label">Email address<sup>*</sup></label><input required="" class="form-control" title="Email address" id="form_Email" type="email" name="form_Email"></div>
<div class="form-group"><label for="form_Company" class="control-label">Company name<sup>*</sup></label><input class="form-control" title="Company name" required="" id="form_Company" type="text" name="form_Company"></div>
<div class="form-group"><label for="custom_Message" class="control-label">Message</label><textarea class="form-control" title="Message" id="custom_Message" name="custom_Message"></textarea></div>
<div><input class="btn-large btn-inverse btn" type="submit" value="Submit"></div>
</form>
</div>
I've tried all the options with:
remDr$findElement()
but get the same error:
Error: Summary: NoSuchElement
Detail: An element could not be located on the page using the given search parameters.
The server is definitely up and working - I've successfully taken a screenshot of the site page.
Can anyone help with how to detect the form elements so I can populate all and send please?

You didn't mention what you tried with findElement(). Here's a minimal working example that includes your form and code that finds and populates the "Full Name" box. First, I write the HTML code for the form to a temporary file:
html <- '<div id="form">
<form accept-charset="utf-8" method="POST" novalidate="">
<div class="form-group"><label for="form_Name" class="control-label">Full name<sup>*</sup></label><input required="" pattern="^***+(.****" class="form-control" title="Full name" id="form_Name" type="text" name="form_Name"></div>
<div class="form-group"><label for="form_Email" class="control-label">Email address<sup>*</sup></label><input required="" class="form-control" title="Email address" id="form_Email" type="email" name="form_Email"></div>
<div class="form-group"><label for="form_Company" class="control-label">Company name<sup>*</sup></label><input class="form-control" title="Company name" required="" id="form_Company" type="text" name="form_Company"></div>
<div class="form-group"><label for="custom_Message" class="control-label">Message</label><textarea class="form-control" title="Message" id="custom_Message" name="custom_Message"></textarea></div>
<div><input class="btn-large btn-inverse btn" type="submit" value="Submit"></div>
</form>
</div>
'
tmp <- tempfile(fileext = ".html")
cat(html, file = tmp)
Load RSelenium, navigate to the page, find the form element, and populate it:
library(RSelenium)
rD <- rsDriver()
remDr <- rD[["client"]]
remDr$navigate(paste0("file://", tmp))
# Find and populate the field
webElem <- remDr$findElement(using = "id", "form_Name")
webElem$sendKeysToElement(list("Foo Bar"))
# Close browser
remDr$close()
You can refer to resources like https://ropensci.org/tutorials/rselenium_tutorial/ for more information.

Related

Issue with routing ASP.Net MVC

When I run the application with ISS after clicking on a class.
The browser starts up with this url. http://localhost:50282/
When I click on Index in my folder Account In Views and
run the application I get this url: http://localhost:50282/Account/Index
Now on both urls I have a register form that links to an action
in my AccountController.
When I submit the form in the second case I get this url:
http://localhost:50282/Account/register and the register method is run in my AccountController Class and works fine.
In the first case I get this url and error:
Url: http://localhost:50282/register
Error: 404
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /register
I want the url to go to the second url http://localhost:50282/Account/register
after clicking register no matter where I clicked before running the application.
Submit form view code:
#{
ViewBag.Title = "Index";
}
<h1>Register Form </h1>
<form action="register" method="post">
<label><i class="" aria-hidden="true"></i> Username </label>
<input type="text" name="Username" placeholder="Enter User Name" required="" />
<br>
<label><i class="" aria-hidden="true"></i> password </label>
<input type="password" name="Password" placeholder="Enter Password" required="" id="myInput" />
<input type="submit" value="Register">
</form>
You need to specify where your form is being submitted to. So change this...
<form action="register" method="post">
<label>
<i class="" aria-hidden="true"></i> Username </label>
<input type="text" name="Username" placeholder="Enter User Name" required="" />
<br>
<label>
<i class="" aria-hidden="true"></i> password </label>
<input type="password" name="Password" placeholder="Enter Password" required="" id="myInput" /> <input type="submit" value="Register">
</form>
To a html helper for your form...
#using(Html.BeginForm("Register", "Account"))
{
<label><i class="" aria-hidden="true"></i> Username </label>
<input type="text" name="Username" placeholder="Enter User Name" required="" />
<br>
<label><i class="" aria-hidden="true"></i> password </label>
<input type="password" name="Password" placeholder="Enter Password" required="" id="myInput" />
<input type="submit" value="Register">
}
Also you need to add antiforgery token for security (#html.Antiforgerytoken()). And decorate Register action with [ValidateAntiforgeryToken] attribute.
See this

What is the purpose of setting a hidden type of input tag? [duplicate]

This question already has answers here:
What's the point of having hidden input in HTML? What are common uses for this?
(12 answers)
Closed 5 years ago.
Full code:
<form accept-charset="UTF-8" action="/" method="get">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓" />
</div>
<label for="first">First name:</label>
<input id="first" name="first" type="text" value="Steve" /><br/>
<label for="last">Last name:</label>
<input id="last" name="last" type="text" value="Jobs" /><br/>
<input name="commit" type="submit" value="Submit" />
</form>
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓" />
</div>
I'm reading the code from another people. I don't understand why he made a fake input field here. Is it for the css purpose?
Hidden fields are used programatically, to pass information about the current page to the server.
Hidden fields can also be used to pass information back to scripts. This may include security tokens, or the name of the relevant row in the database. The user does not need to see this data, but it is passed back to the server on submission so that scripts function correctly behind the scenes.

Retrieving a URL via a Wufoo Form

I'm pretty new to using wufoo forms and have been searching for a few days and can't quite find what I'm looking for.
I did find a number of articles about 'URL Modification' but not sure how to implement this for what I need.
We have a simple single wufoo form which is being used across 6 iterations of a client's domains (they are sector specific).
We want (in the email notification and response entry on wufoo) to record which site was used to complete the form (for analytical purposes).
In other words the email to the client should list:
Name: John Smith
Email: Johnsmith#mail.com
Phone: 555-123-1234
From: www.websiteversion1.com
The form is being integrated on Wordpress sites.
Any help would be appreciated!
You can copy the form HTML to your site's templates and modify the form, using PHP to fill in the value of the site url. I don't think WuFoo will automatically fill that field in for you.
First of all, in your WuFoo account forms manager, add a website (url) field and make it visible for admins only (this is a Wufoo option).
Then copy the generated form into your own template.
Now modify your form template so that it grabs the site URL and fills it in for the value of the website field where you want it.
Your form template might look something like this:
<form class="wufoo-form" id="form3" name="form3" accept-charset="UTF-8" autocomplete="off" enctype="multipart/form-data" method="post" novalidate action="#">
<div class="form-group">
<label for="Field1">Name</label>
<input id="Field1" name="Field1" type="text" placeholder="" value="">
</div>
<div class="form-group">
<label for="Field2">Email</label>
<input id="Field2" name="Field2" type="email" placeholder="" value="">
</div>
<div class="form-group">
<label for="Field3">Phone</label>
<input id="Field3" name="Field3" type="tel" placeholder="" value="">
</div>
<div class="form-group hidden">
<label for="Field4">From</label>
<input id="Field4" name="Field4" type="url" class="form-control" placeholder="" value="<?php esc_url( home_url() ); ?>">
</div>
<div class="form-group">
<button id="saveForm" name="saveForm" type="submit" name="submit" class="btn btn-primary btn-lg">Let's talk!</button>
<input type="hidden" id="idstamp" name="idstamp" value="***the_id_for_your_form_wufoo***" />
</div>
</form>

Place holders in wordpress

I have problem with placeholders in Wordpress Onetone theme. When I change text in placehoder tags to my preferred text it works, until I press on that field again and then text resest to it's older text. For example, I change "Email" to word "whatever" , save it, go to website, it shows word "whatever" in input area, and when i press with mouse on that area and then somewhere else, it resets back to "Email". How I could make that my text in placeholder would be permanent?
<div class="contact-area">
<form class="contact-form" method="post" action="">
<input type="text" name="name" id="name" value="" placeholder="Name" size="22" tabindex="1" aria-required="true">
<input type="text" name="email" id="email" value="" placeholder="Email" size="22" tabindex="2" aria-required="true">
<textarea name="message" id="message" cols="39" rows="7" tabindex="4" placeholder="Message"></textarea>
<p class="noticefailed"></p>
<input type="hidden" name="sendto" id="sendto" value="tomas#bandymasvienas.esy.es">
<input type="button" name="submit" id="submit" value="Post">
</form>
</div>
I found a problem. If you want to be text all time same, you need to find your .js file with your desired function and edit text in there and placeholders will show text you want.

Value in the submission form

I've create a RSS submission form and I want to show in the input box something like Enter your email here...., and when they click on it that message should be disappear and they can put their email in the box.
Here is the code I'm using at the moment
<div id="RSS">
<form action="http://feedburner.google.com/fb/a/mailverify" class="RSS" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=RSS', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true">
<input type="hidden" name="uri" value="RSS">
<input type="hidden" name="loc" value="en_US">
<input name="email" id="RSS-text" type="text" maxlength="100" style="width:160px !important" value="Enter your email address..." class=""><button type="submit" id="RSS-button">Subscribe</button>
</form>
</div>
The problem is that it doesn't disappear when someone click on it, and I saw many forms including my search form it can be done that way.
You can use the placeholder attribute, but it doesn't support IE:
<input type="text" placeholder="Enter your text here..." />
Otherwise you can use a bit of javascript:
<input type="text" onfocus="if(this.value=='Enter your text here...') this.value='';" onblur="if(this.value=='') this.value='Enter your text here...';" value="Enter your text here..." />

Resources