Capybara fill_in with xpath - ruby-on-rails-4

I have multiple input fields with one id specification, but they have different attributes. I can find them just fine, but am having trouble figuring out how to use the fill_in with the find appropriately. Currently I have:
find('//input[#id="specification"][#data-number="1"]').fill_in with: "This first sleeping bag should be 0 degrees F"
Error-- Capybara::Webkit::InvalidResponseError:SYNTAX_ERR: DOM Exception 12
Thanks!

The first is that fill_in will look for a text field within the element returned by find. Basically you are asking Capybara to find something like:
<input id="specification" data-number="1">
<input type="text">
</input>
This is unlikely to exist.
Given that you have already found the text field using find, you want to use the set method to input it:
find('//input[#id="specification"][#data-number="1"]').set("This first sleeping bag should be 0 degrees F")
Assuming you have not changed the default_selector to :xpath, the above will still fail due to the expression not being a valid CSS-selector. You need to also tell Capybara that an :xpath locator is being used:
find(:xpath, '//input[#id="specification"][#data-number="1"]').set("This first sleeping bag should be 0 degrees F")

It's not valid HTML to have multiple elements with the same id. You should start by changing that.

Related

Have screen reader pronounce Country codes in a text input as individual letters

I am working on an Angular app that displays selected Country codes in a text field. This input displays Country codes because of space constraints:
<input type="button" #countryListTrigger matInput readonly i18n-placeholder placeholder="COUNTRIES" [ngModel]="selectedCountries" />
Here's what the control looks like with Country codes displayed:
Countries Widget
Right now, screen readers would read the AU like the letter "o" and AT like "#". I know about the tag, but is there a way to achieve the same result on an input value? Otherwise, I could add another (hidden) control that is read instead perhaps?
It starts getting messy if you try to force a screen reader to announce things phonetically. If you add an aria-label that has aria-label="A U" or aria-label="A T", then braille users will be out of luck because they'll read "A space U".
It's unfortunate there isn't really a good solution for this. The screen reader user can read the input value one character at a time so if it sounds weird to them, they have a work around. It's not a great user experience but having screen readers mispronounce stuff has been a problem for a long time.

How to list only item containing string X in a string Y from a dictionnary in Jinja2

I’m trying to obtain the count of all title containing a specific string from a dictionary in a jinja template.
I have tried many variant with select and other test and haven’t found the right way to do so.
This is not for ansible for which I have found many solutions to fix this issue.
Also the test equalto does not work since I do not have an exact match on the string and doesn’t seem to take regex.
{{ Dictionnary | selectattr("title", "in","MyString") | list | count }}
It seems that the string never gets properly evaluated because it always returns 0.
The selectattr without test return the right number of total titles.
I wonder if we could evaluate it with an if statement somehow.

ColdFusion autosuggest only matching start of string

I am working with the autosuggest attribute of cfinput.
But I am not 100% satisfied with how it works.
Here's a little bit of the code :
<cfinput id=""town" name="town" type="text" class="form-control" autosuggest="cfc:bind.gettown({cfautosuggestvalue})" showautosuggestloadingicon="false>
This control suggests all of the towns with the cfautosuggestvalue in it.
Ex: if it contains "lu", it should show all the cities containing this string, like: Luxembourg or Saint Jean-de-Luz
But it is only showing Luxembourg ...
I checked my request bind.gettown and it gives me those 2 cities, but I guess that the ColdFusion's autosuggest filters my initial request by removing all the string not starting by 'lu' ... and as you can guess this is a problem.
So my point is to show all the cities containing 'lu' ...
Can you help me?

Construct Xpath

I have the following repeated piece of the web-page:
<div class="txt ext">
<strong class="param">param_value1</strong>
<strong class="param">param_value2</strong>
</div>
I would like to extract separately values param_value1 and param_value2 using Xpath. How can I do it?
I have tried the following constructions:
'//strong[#class="param"]/text()[0]'
'//strong[#class="txt ext"]/strong[#class="param"][0]/text()'
'//strong[#class="param"]'
none of which returned me separately param_value1 and param_value2.
P.S. I am using Python 2.7 and the latest version of Scrapy.
Here is my testing code:
test_content = '<div class="txt ext"><strong class="param">param_value1</strong><strong class="param">param_value2</strong></div>'
sel = HtmlXPathSelector(text=test_content)
sel.select('//div/strong[#class="param"]/text()').extract()[0]
sel.select('//div/strong[#class="param"]/text()').extract()[1]
// means descendant or self. You are selecting any strong element in any context. [...] is a predicate which restricts your selection according to some boolean test. There is no strong element with a class attribute which equals txt ext, so you can exclude your second expression.
Your last expression will actually return a node-set of all the strong elements which have a param attribute. You can then extract individual nodes from the node set (use [1], [2]) and then get their text contents (use text()).
Your first expression selects the text contents of both nodes but it's also wrong. It's in the wrong place and you can't select node zero (it doesn't exist). If you want the text contents of the first node you should use:
//strong[#class="param"][1]/text()
and you can use
//strong[#class="param"][2]/text()
for the second text.

How to change a node's property based on one of its other properties in Neo4j

I just started using Neo4j server 2.0.1. I am having trouble with the writing a cypher script to change one of the nodes property to something based one of its already defined properties.
So if I created these node's:
CREATE (:Post {uname:'user1', content:'Bought a new pair of pants today', kw:''}),
(:Post {uname:'user2', content:'Catching up on Futurama', kw:''}),
(:Post {uname:'user3', content:'The last episode of Game of Thrones was awesome', kw:''})
I want the script to look at the content property and pick out the word "Bought" and set the kw property to that using a regular expression to pick out word(s) larger then five characters. So, user2's post kw would be "Catching, Futurama" and user3's post kw would be "episode, Thrones, awesome".
Any help would be greatly appreciated.
You could do something like this:
MATCH (p:Post { uname:'user1' })
WHERE p.content =~ "Bought .+"
SET p.kw=filter(w in split(p.content," ") WHERE length(w) > 5)
if you want to do that for all posts, which might not be the fastest operation:
MATCH (p:Post)
WHERE p.content =~ "Bought .+"
SET p.kw=filter(w in split(p.content," ") WHERE length(w) > 5)
split splits a string into a collection of parts, in this case words separated by space
filter filters a collection by a condition behind WHERE, only the elements that fulfill the condition are kept
Probably you'd rather want to create nodes for those keywords and link the post to the keyword nodes.