Xpath query to select node when attribute does not exist? [closed] - xpath

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 14 years ago.
Improve this question
I want to select nodes for which a specific attribute does not exist. I've tried the Not() function, but it doesn't work. Is there a way for this?
Example:
The following Xpath query:
group/msg[not(#owner)]
Should retrieve the first node but not the 2nd one. However, both SketchPath (tool to test Xpath queries) and my C# code consider that the 2 nodes are ok.
<group>
<msg id="EVENTDATA_CCFLOADED_XMLCONTEXT" numericId="14026" translate="False" topicId="302" status="translated" >
<text>Context</text>
<comment></comment>
</msg>
<msg id="EVENTDATA_CCFLOADED_XMLCONTEXT_HELP" numericId="14027" translate="False" topicId="302" status="translated" owner="EVENTDATA_CCFLOADED_XMLCONTEXT" >
<text>Provides the new data displayed in the Object.</text>
<comment></comment>
</msg>
</group>
In fact the Not() function works correctly, it's just that I had other conditions and parentheses weren't set correctly. errare humanum est.

In some old and not very standard XPath engine I had to use string-length(#attr)=0 for the same reason.

Works for me when testing with XPath Explorer (based on Jaxen library).
So I guess it is indeed depending on the XPath implementation.

Related

what are the advantages and disadvantages of using "xpath" in selenium? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am pretty new to selenium and the website I am testing is in HTML5 and there are no ID's on all the elements. SO, I have to find a unique pointer for all those elements I click. I found that Xpath could help a bit. But the website UI will be changing frequently. So, I want to know that what attribute could be a perfect alternative to xpath ?
Thanks in advance.
You don't really have advantage of using xpath, you will have to change it all the time, on every build. Just don't use it, make agreement with dev team to set ids on everything.
If website Ui will be changing frequently don't use xpath. One line added will change all xpath you use. Request from the dev team to set id locators to all elements.
Xpath reliability can be massively increased by using relative xpath rather than absolute.

Storing the object of Select_list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Please consider the below code
a=b.select_lists[0]
a.select("Agent")
In the aforementioned code, the first line is taking so much time, So Can anyone tell me Is there any way to store value of "a" object for further use without getting from b.select_lists[0]? Or Is there anyway can we directly get the value of 'a'?
The code which I am trying to write for the select list follows below
<select class="ng-valid ng-dirty" style="" ng-change="selectionsAgentType(AgentType)" ng-model="AgentType"> <select class="ng-valid ng-dirty" ng-change="AgentCategorySelected(agentoptions)" ng-model="agentoptions">
If option with text: 'Agent' is unique on this page.
If you need just simulate select
b.option(:text, 'Agent').select
Also, if you need value of this option
a = b.option(:text, 'Agent').value
Else,
b.select_lists.first.option(:text, 'Agent').select
a = b.select_lists.first.option(:text, 'Agent').value

Parsing using scan and regex [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need to use scan in particular to get the data and the data only between two values using scan and a regex expression.
The values aren't static so I can't match using them.
Let me rephrase it, i need the value only. So something that allows me to get everything after id="results" value=" and before "
id="results" value="/randompath/lol.jpg"
I got no clue what you're actually searching for but if you want to extract the value of the attribute value in that string (assuming double quotes).
You can use this regex:
(?:^|\s|")value(?:\s+)?=(?:\s+)?(?:"((?:\\.|[^"])+)")
But for sure any html/xml parser like Nokogiri would be better if you can use one.

Ruby detect if a column value has changed [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So I have this line:
if self.company_changed?
And it works fine but this detects if the company has changed on the object. I need to know if the database value has changed and not if the value in memory has changed. So I tried this:
if :company_changed?
This seems to work in debug mode when I only execute the one line. If I let it run, it fails in testing on an infinite loop.
My question is what can be used in ruby to check to see if the column value has actually changed.
I'm pretty sure you're actually talking about ActiveRecord. In which case, you'd need to re-fetch the record to see if the value has changed in the database.
self.class.find(self.id).company != self.company
A general purpose method for this might be something like:
def attr_changed_in_db?(attr)
self.class.find(self.id).attributes[attr] != self.attributes[attr]
end
There is an excellent screencast on this by the great Ryan Bates.

what is the command object in spring framework [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could you please explain about command object in spring frame work with an example?
from Spring Documentation:
Command Object - a JavaBean which will be populated with the data from your forms
Think of Command Object as a POJO/JavaBean/etc.. that backs the form in your presentation layer.
Once the form is submitted, all the individual attributes are mapped/bound to this object. On the way up to presentation, Command Object properties may be used to pre/populate the form.
check an example here

Resources