How to get value between "::before" and "::after" using Xpath? - xpath

How should I modify my xpath:
//#*[contains(., 'order-num')]
to get number of orders after
::before
from this screenshot?
Page for test.

You need
//span[#class="order-num"]/text()
to get required value

Try this expression:
substring-after(//span[contains(#class,'order-num')][1]/text(),'::before')

Related

Adress div in XPath with nested properties inside this div

we want to automate an web application with Robot framework/SeleniumLibrary. The app contains some tables, which do not have simple unique identifiers like id/name/class... They only can be uniquely identified via a nested property. Here a sample excerpt of the properties window (DevTools)
grid: window.<computed>
> FormSubmitOnlyChanged : true
> ...
> _dataprocessor: dataProcessor
> autoUpdate: false
> ...
> serverProcessor: "/TEST/GridNew/multi?group=getMetaData&name=Sources&editing=true"
> ...
> ...
...
The Element looks as following:
* The id parameter contains an dynamic id and can therefore not be used for object identification.
We tried some approaches, e.g.
//div[contains(#grid._dataprocessor.serverProcessor, 'group=getMetaData&name=Sources')]
or
//div[contains(#serverProcessor, 'group=getMetaData&name=Sources')]
but none of them did work. Does anybody have an idea how to get an XPath that makes it possible to contain the nested property? Thank you in advance.
Please try this XPath:
"//div[contains(., 'group=getMetaData&name=Sources')]"
The dot . means here any attribute containing group=getMetaData&name=Sources value.
Also, I see the parent element in the shared picture is hidden. Maybe this causes your problems?
Please try this below xpath:
//div[starts-with(#id,'cgrid2_')]
The developers now managed it to set an id manually to overwrite the generated dynamic ID. Furthermore, after more research, it seems to be not possible to use this property for XPath.

How to generate Laravel Link with anchor

I use Laravel URL::Route for link pages, And I passed query string like following code, but how to add anchor tag for this?
eg: myproject.local/projects?week_ending=value#anchor
How to do that #anchor part with URL::Route? thank you
URL::Route('projects', array('week_ending'=>$week_end_day))
The most obvious way for that will be:
URL::Route('projects', array('week_ending'=>$week_end_day)) . '#anchor'

eZPublish - how to get Selection value?

I created (in admin) a selection field called color. Now I can't access it. When I run {$note.data_map.color.content|attribute(show)} it prints value. But I can't access it without attribute(show). What can I do?
eZSelection's content is an array, access the 0 key on content to get the value.
{$node.data_map.email_option.content.0}
don't forget you always have attribute_view_gui* which can help you quite a lot in these cases.
you can set the attribute to be information collector and collect that information from user.
*{attribute_view_gui attribute=$node.data_map.color}
You need to match the option array defined in your class attribute with the id of the selected option in order to get the value of it.
$node.data_map.color.class_content.options will contain all the options available (associative array with id and name values)
$node.data_map.color.content is an array containing the ids of the selected options (because this field can handle multiple selection).
Even if the {section} function is deprecated I'll suggested that you have a look at the default template rendering an ezselection attribute : design/standard/templates/content/datatype/view/ezselection.tpl
If you have "Multiple choice" type than you can do it like this:
{if $node.data_map.color.has_content}
{foreach $node.data_map.color.content as $colorID}
{foreach $node.data_map.color.class_content.options as $opt}
{cond($opt.id|eq($colorID), $opt.name, '')}
{/foreach}
{/foreach}
{/if}

Capybara field.has_css? matcher

I'm using following spec with MiniTest::Spec and Capybara:
find_field('Email').must_have_css('[autofocus]')
to check if the field called 'Email' has the autofocus attribute. The doc says following:
has_css?(path, options = {})
Checks if a given CSS selector is on the page or current node.
As far as I understand, field 'Email' is a node, so calling must_have_css should definitely work! What I'm doing wrong?
Got an answer by Jonas Nicklas:
No, it shouldn't work. has_css? will check if any of the descendants
of the element match the given CSS. It will not check the element
itself. Since the autofocus property is likely on the email field
itself, has_css? will always return false in this case.
You might try:
find_field('Email')[:autofocus].should be_present
this can also be done with XPath, but I can't recall the syntax off
the top of my head.
My solution:
find_field('Email')[:autofocus].must_equal('autofocus')
Off top of my head. Can you use has_selector?(). Using Rspec wit Capy:
page.should have_selector('email', autofocus: true)
Also check Capybara matchers http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers
I've not used MiniTest before but your syntax for checking for the attribute looks correct.
My concern would be with your use of find_field. The docs say:
Find a form field on the page. The field can be found by its name, id or label text.
It looks like you are trying to find the field based on the label. If so I would check that you have the for attribute on it and and that it has the correct id of the form field you are looking for. To rule out this being the issue you could temporarily slap an id your form field and look for that explicitly.

To check the default select value tag!

I have a question.Here is the code!
f.select(:departments,Department.all.collect{|c|[c.name,c.id]},{},:size=>10,:multiple => ture)
class Emergency
has many :departments
end
the html source like this:
<select id="emergency_departments" multiple="multiple" name="emergency[departments][]" size="10"><option value ="">""</option>....</select>
now I want to get the default selected tag , who can tell me how ?
You want to find the value of the option selected? Is that right?
If so, and you know your way around a bit of JQuery, this is how you do it:
$("#emergency_departments option:selected").val()
Now I know the question , i used the tag "collection_select" to solve this problem.Its method like this,
f.collection_select(:departments,Department.all,:id,:name,)

Resources