Ruby / Mechanize aborts when it finds an accentuated u letter - ruby

I want to read this form of a php script using Ruby/Mechanize:
<form name="editevent" method="post" action="/index.php" enctype="multipart/form-data">
<input type="text" name="veranstaltung">
<select name='ortid'>
<option value='2'>Kaminwerk</option>
<option value='3'>Pitú</option>
<option value='4'>Apollo-Center</option>
</select>
<input type="text" name="neutermin" id="neutid" />
<textarea name="beschreibung" cols="40" rows="7"></textarea><br />
<input type="submit" name="button" value="Absenden">
</form>
In Ruby I have got:
form = page.forms.first
form.fields.each { |f| puts f.name }
However Ruby can find only the form elements with the name "veranstaltung" and "ortid"
I found out that the problem ist the "u" letter with the accent on it in the word "Pitú". Proofs: when I print the inner_html of the html code the part of the form looks like this:
<form name="editevent" method="post" action="/index.php" enctype="multipart/form-data">
<input type="text" name="veranstaltung">
<select name='ortid'>
<option value='2'>Kaminwerk</option>
<option value='3'>Pit</form>
The other part of the form has vanished! How can I use that form completely despite of the "ú"?
I would be very glad if anyone could help.

What version of Ruby? It smells like 1.8.7, which is not Unicode savvy. If you can, upgrade to 1.9.2.
It's also important to specify the code-set of the language when parsing the content. Often times that information is in the DOCTYPE statement, but if it isn't you have to give the language a hint of what to expect.
Because those characters are embedded in PHP, they could be UTF-8, or maybe a variant of WIN-1252 or ISO-8951 which implies they'd be a single byte character. Mechanize uses Nokogiri to parse, and it will want to know what the language is to give you the best decoding of the values. Nokogiri will put errors in the errors attribute when it can't parse something to its liking, so you might want to check there.
SO, if I were you, I'd look to see what the DOCTYPE is when the content is sent, and also check the HTTP headers, and see if something will define the codeset.
This is a problem I've encountered many times on the internet because HTML is so poorly written and so often fails to follow the specs.

Related

Form input old value in laravel 5.6

I have a search form input where i want to display the searchterm value in the searchbox after searching on the results page.
I tried the following which is not working
<input type="text" name="search" value="{{ old('search') }}" placeholder="Search help articles" class="form-control form-control-gray col-md-10">
What is incorrect in the value=""
old() is used when flashing data to the session. This is mostly used for forms which involve redirects back when something fails. Read about old input here.
request() should be used here since you're wanting to display the value that was submitted on that request.

TYPO3 realURL rewrite News Tag Search

I'm using TYPO3 7.6.x with realURL 2.0.14 ans news 4.2.1.
I've made a SearchForm-Module, where I can search for Newstags.
Here's my HTML-Output, I'm just looking (TS) for tx_news_domain_model_tag.title at my pidInList=20 and it works:
<form method="get" action="/index.php">
<input type="hidden" name="id" value="14">
<select class="tagSearch" name="tx_news_pi1[overwriteDemand][tags]">
<option value="" selected="">Tags</option>
<option value="12">Tag A</option>
<option value="8">Tag >B</option>
...
</select>
</form>
At the moment my Links are like:
http://www.example.com/index.php?id=14&tx_news_pi1%5BoverwriteDemand%5D%5Btags%5D=15
If I click on a news tag below my news record, I'll get:
domain.com/articles/tagname/
How can I tell realURL, to rewrite tx_news_pi1[overwriteDemand][tags] from my selectbox? At the moment I use the realURL-Configuration from Ext.news (advanced setup)
Unfortunately this has nothing to do how the RealUrl works, since it is the default browser behaviour of submitting a form, which generates the non-user friendly URL.
The easiest way to fix it would be to rewrite the form into a list with <a href=""> links. These links will get processed automatically with RealUrl.
Instead of using an ul/li you could also generate the url in the value attribute of the option and after form submit, redirect via JS to the selected URL

How to get value from a placeholder using xpath

All of the elements are dynamic. I can see only Placeholder which is unique from the following html:-
<input
id="ext-gen1617"
type="text"
size="20"
class="x-form-field x-form-text x-form-focus"
autocomplete="off"
aria-invalid="false"
placeholder="Gender"
data-errorqtip=""
role="textbox"
aria-describedby="combobox-1166-errorEl"
aria-required="true"
style="width: 78px;"
/>
I need to get the value displayed in
placeholder="Gender".
I tried using
//input[#placeholder='Gender']
But my webdriver script failed to identify it.
Can anyone please help me out with possible solution to it?
String s=driver.findElement(By.xpath("//input[#placeholder='Gender']")).getAttribute("placeholder");
System.out.println(s);
To get an attribute for a filed, you can use the .getAttribute() method.
I assume you are dealing with (front end)script generated web elements, then you must need to embrace lean way of thinking. Don't try to pull out a web element by it's property alone. If you are not getting them try to build a xpath from its parent or siblings.
say, the HTML goes like this,
<div id="somestatic id">
<div id="xyz">
<input name="dynamic one"/>
</div>
</div>
Then you can build a xpath as ,
//*[#id='staticID']/div/input
for the HTML,
<div id="staticID"></div>
<input name="dynamic one"/>
the xpath is ,
//*[#id='staticID']/following-sibling::input
similarly there are n number of option available. Give them a try
Try
driver.findElement(
By.cssSelector("input[id*='ext-gen']")
).getAttribute("placeholder")
Let me know is the above statement is working or not.
The best way is to find the element with CSS selector in this case -
input[placeholder='Gender'], which can easily find the element.

Hidden inputs are missing from Request in Asp.net mvc3

I'm using asp.net mvc3 ajax.beginform, and recently I've encountered a very strange problem.
It seems that some of the hidden input's I've placed inside the form do not exist in the request object.
I am not changing these values in any way after the post.
Any idea what is the reason?
Here's an example of a form that's giving me some trouble.
<form action="/PriceListItems/PriceUpdate" data-ajax="true" data-ajax-method="Post" id="form0" method="post">
<input id="item_Id" name="item.Id" type="hidden" value="3">
<input id="price_TariffId" name="price.TariffId" type="hidden" value="1">
<input class="input-mini"
data-val="true"
data-val-number="The field Price must be a number."
data-val-regex="incorrect number"
data-val-regex-pattern="(^N/A$)|(^[-]?(\d+)(\.\d{0,3})?$)|(^[-]?(\d{1,3},(\d{3},)*\d{3}(\.\d{1,3})?|\d{1,3}(\.\d{1,3})?)$)"
data-val-required="שדה זה הינו חובה"
id="itemTariff_3_1"
name="price.Price"
onchange="postThis(this);"
type="text"
value="300.00">
<span class="help-block">
<span class="field-validation-valid"
data-valmsg-for="itemTariff_3_1"
data-valmsg-replace="true"></span>
</span>
</form>
Thanks!
solved it, but it was quite a disappointing solution..:
i've replaced every jquery related script in my site so that it'll arrive from a CDN rather from my local files, but in the original versions.
and that was it.
everything suddenly started to click together.
frustrating, but works.
thanks,
Nir

Freemarker rendering differently on IE8

we have a template that uses this for the record line
<input type="${inputType}" name="${variableName}.code" id="${variable}.${vnum}.${answer.code}" class="checkbox" value="${answer.code}"
[#nested/] [#if (answer.textLength > 0) && scripting]onchange="showOtherBox( this, '${variable}.[#if descriptionHack]${variableNumber}[#else]${vnum}[/#if].${answer.code}.description' )"[/#if]
[#if showValues && (existing == answer.code)]checked="checked"[/#if]/>
On IE8 it renders as this
<span class="field">
<INPUT id=responses.8.L class=checkbox value=L type=checkbox name="responses['8'].answers['L'].code">
<LABEL for=responses.8.L>Award(s) for special accomplishment or performance related to activity participation (please list)</LABEL>
<TEXTAREA id=responses.8.L.description class=" visible" rows=4 cols=60 name="responses['8'].answers['L'].description"></TEXTAREA>
</span>
and on every other browser we tried, it renders as this
<span class="field">
<input type="checkbox" name="responses['8'].answers['L'].code" id="responses.8.L" class="checkbox" value="L" onchange="showOtherBox( this, 'responses.8.L.description' )">
<label for="responses.8.L">Award(s) for special accomplishment or performance related to activity participation (please list)</label>
<textarea rows="4" cols="60" name="responses['8'].answers['L'].description" id="responses.8.L.description" class="visible" classname="visible"></textarea>
</span>
The difference being that in the FTL script, the if statement
[#if (answer.textLength > 0) && scripting]
is true for everything except IE. In IE8 its false for some reason and therefore it does not put the OnChange javascript event on the input tag. Has anyone seen anything like this before? we are using Freemarker 2.3.9
Update, it kinda works if i turn compatibility mode on for IE8. but not exactly. when i do that, the onchange event doesn't fire until the check box loses focus. which is very different than everything else. Is there a quick way to fix this without too much trouble? i suppose i could put something in that says if ie8, insert onclick instead of onchange. that may work, but i would need an authorization from the client to fix it like that.
Since FreeMarker runs on the server only, it's not influenced by the browser directly. You should put something like <!-- answer.textLength = ${answer.textLength}, scripting = ${scripting?string} -->) before that [#if], so that you can see why exactly the condition fails, then find out where the value of the problematic variable is coming from, because usually it's not FreeMarker that sets it. (Bare-bone FreeMarker can't even detect the browser type.)

Resources