capybara find and save text value from a page - regex

i am in the process of writing a Capybara Automation suite. one thing that i am trying to do is extract a value between the td tags from the html source
<td class="table-column-data">CB/AE9999XX/A001</td>
i.e. find and extract the value CB/AE9999XX/A001 then save it into a variable to use later on.
i hope you can help
thanks

saved_text = find("td.table-column-data").text
Will get the text from the element - obviously the selector passed needs to select a unique element, which will depend on the surrounding html

You can use the below mentioned way to extract and save the value in a variable:
extractedValue = find('.table-column-data').text
This will fetch the text "CB/AE9999XX/A001" and store it in the variable "extractedValue".
Apart from this, you can also extract the text using jquery as shown below:
extractedValue = page.evaluate_script("$('.table-column-data').text()")
Hope this helps :)

Related

extract value from the url by using a regex

I have this string value
var x = '/index.cfm?act=page1.showdata';
want to extract page1
if i had to use it as simple, i am use contains to find it and make it work, but i really want to use regex to find that value and put it into a variable,
using coldfusion
No need for regex. Every query string parameter is available in the url scope. They're all already variables.
<cfdump var="#url#">
This dumps a struct whose keys are the parameters.
So the CF variable url.act has a value (string) of page1.showdata.
What else do you need than that?

Enterprise Architect document creation - filter

Enterprise Architect was introduced to me only today, and i also got a task related to document generation, which should be done as soon as possible.
I have to write a template for doc generation, and this template should do some filtering or conditioning on a specific element.
From a closer look: I have an element, which has a special field {Element.SpecialField}, that can hold values of true or fase. If the field's value is true, then the field's name should be generated into the doc, else nothing.
Which is the easiest way to do this? Scripting or selector/fragment filters? Thanks.
EDIT:
The generated document should look something like this:
![EA Document]: http://s29.postimg.org/68edfthdz/EA_doc.jpg
The cells containing question marks are the specific element values I mentioned above the EDIT section.
There are three element fields: TagValue_X, TagValue_Y and TagValue_Z.
They can be true or "" (empty string) individually.
But in the table cell I don't want to see their values, but the names of the fields separated by commas. For example: if
{Element.valueOf(X)} == true AND {Element.valueOf(Y)} == "" AND {Element.valueOf(Z)} == true
, then the cell should contain "X, , Z".
EDIT 2: To Geert's answer.
The following script works well, when I want to to search in the Model (CTRL+ALT+A in EA 12):
SELECT t_objectproperties.Property FROM t_object, t_objectproperties
WHERE t_objectproperties.Value='True'
AND t_objectproperties.Property='X'
AND t_object.Object_ID = t_objectproperties.Object_ID
How should I modify this to apply it as a Custom Query in the fragment template? I tried some queries like this, but they never returned anything. Probably this is a basic conceptual misunderstanding issue from me...
SELECT t_objectproperties.Property AS SomeQuery
FROM t_objectproperties
WHERE t_objectproperties.Value='True'
AND t_objectproperties.Property='X'
AND t_objectproperties.Object_ID = #OBJECTID#
TemplateMain:
package>
element>
{Template - TemplateFragment}
<element
<package
TemplateFragment:
custom>
{SomeQuery}
<custom
I suppose the fragment template should be inserted into the element section.
The easiest solution would be to create an SQL fragment.
Using SQL you can return exactly the fields you need based on the PackageID passed to the template fragment.
Check the learning center (Alt-F1) for a step-by-step guide on creating SQL fragments.

how to match a field name with another field name

I have two fields that run throughout a website that I would like to match so that when a user inputs a value either of the fields, it will match the other field. I'm using Sitecore Rocks and am trying to use a query to do this.
select ##h1#, ##Title#
from /sitecore/Content/Home//*[##h1# !="##Title#"];
update set ##h1# = ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
What am I missing here?
This article talks about tapping in to the item:saving event which allows you to compare the fields values of the item before and after the changes:
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Intercepting-Item-Updates-with-Sitecore.aspx
Using this, you can determine which field has been amended, then change the other to match.
I've had to do something similar to this when a new field was added, and we wanted to set the initial value equal to an existing field. It may be a bug in Sitecore Rocks, but I found it would only update a field when a static value was part of the query.
When I ran ##h1# = ##Title#, the query analyzer would return the correct number of items updated, but no values were actually updated. However, ##h1# = '<id>' worked perfectly. After trying a number of things, I found this did what I wanted.
update set ##h1# = '' + ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
I hope that helps.

Sitecore Fast Query select attribute values

Is there a way by using XPath Builder under Developer Center inside Sitecore Shell (a Fast Query interface) to select a particular attribute from an item. Example:
/sitecore/content/Home/Products/*[##templatename = 'Product Group']/#id
I would expect to see a collection of id's to be returned where id is an attribute of an item. If yes is it possible to extract an attribute with a space bar? Example:
/sitecore/content/Home/Products/*[##templatename = 'Product Group']/#more info
EDIT
The thing that I want to achieve is to get a collection of items (I have few hounded items here), not one particular item. That's why I am not interested in adding additional conditions, like specific item id or title. I want to see a collection of values of a specific attribute. As in example showed above, I want to see a collection of values that are assign to 'more info' attribute. Once again I am expecting to see few hounded different values that are set to 'more info' attribute.
EDIT2
There is a problem with a production, a critical stuff. There is no access to it other then thru Sitecore shell, but I don't have permissions to add/install additional packages. I know how to get this info by implementing custom code, or queering db directly, but I simply do not have permission to do it. Guys that will be able to grant me need credentials will wake up in 6 hours, so I was hoping to do whatever I can to analyse the situation. I would accept Maras answer if it was an answer not a comment - there is no way I can do it using fast query. thanks for help.
Try using #
/sitecore/content/Home/Products/*[##templatename = 'Product Group']/##more info#
This is the way around when selecting items with fields that contain spaces. Having said that I don't know if you would be able to get a specific result or not for your specific question but give it a try.
For example, consider this query which returns Product S1
fast:/sitecore/content/home/*[#Title = 'Item 1' and ##templatename = 'Product Group1']//*[#Title = 'Product S1' and ##id = '{787EE6C5-0885-495D-855E-1D129C643E55}']
However, if you place the special attribute (i.e. ##id) at the beginning of the condition, the query will not return a result.
fast:/sitecore/content/home/*[##templatename = 'Product Group1' and #Title = 'Product S1']//*[##id = '{787EE6C5-0885-495D-855E-1D129C643E55}' and #Title = 'Product S1']
Remember this, Sitecore Fast Query only supports the following special attributes:
##id
##name
##key
##templateid
##templatename
##templatekey
##masterid
##parentid
Let us know if this helps.

How do I search a db field for a the string after a "#" and add it to another db field in django

I want to have a content entry block. When a user types #word or #blah in a field, I want efficiently search that field and add the string right after the "#" to a different field as a n entry in a different table. Like what Twitter does. This would allow a user to sort by that string later.
I believe that I would do this as a part of the save method on the model, but I'm not sure. AND, if the #blah already exists, than the content would belong to that "blah"
Can anyone suggest samples of how to do this? This is a little beyond what I'm able to figure out on my own.
Thanks!
You can use regex (re) during save() or whenever to check if your field text contains #(?P<blah>\w+) , extract your blah and and use it for whatever you want .