Getting all elements in Selenium - python-2.7

I am very new in Selenium. I have came across a line of code which I can't understand.
allElements=sBrowser.find_elements_by_xpath(".//a[#class]")
I tried several places the answer I got is, it is finding all the anchor tag in the browser. but what does the
'.'
means before
//a[#class]

//y
will still find any node, y, located anywhere within the XML tree. But, the XPath:
.//y
will find any node, y, that is a descendant of the node x. In other words, preceding the // expression with a . tells the XML search engine to execute the search relative to the current node reference.
Referance: http://www.bennadel.com/blog/2142-using-and-expressions-in-xpath-xml-search-directives-in-coldfusion.htm

Related

How to recover the ParserRuleContext for a specific line and character position with antlr4?

Once I have initialised the parser, lexer and obtained the translationUnit context, how can I jump directly to the (closest) ParserRuleContext that contains a specific line and character position in antlr4 (CPP runtime) ?
Usually I m using the Listener pattern to walk through the translationUnit context. In every visited context, I can obtain the corresponding line and character position of a context using the following code :
antlr4::Token* tokenclass = _tokenstream->get(myContext->getSourceInterval().a); // use ".b" if end of interval is needed
size_t CharPositionStartInLine = tokenclass->getCharPositionInLine();
size_t LineStart = tokenclass->getLine();
I would like to perform the opposite: to obtain a token from a specific line and char position, and then to obtain the (first) parent context. Is it possible ?
I think I can achieve what I want (i.e to find a context based on line and character position) by checking every line and character position of context inside the function enterEveryRule(antlr4::ParserRuleContext* context) but it seems overcomplicated. So is there an easier way to recover the ParserRuleContext for a specific line/character position ?
The approach is pretty simple. A ParserRuleContext contains start and stop tokens with positioning information. Hence it is easy to tell if a rule context includes a specific position. Start with the parse tree root and iterate over its children. Find the one that includes this position (overlap is not possible). Continue with that node and its children until you find a terminal node, which is the one you are looking for. If for a given node no child includes the given position then use that node instead.
In the MySQL Workbench Sources there's a C++ implementation for terminalFromPosition and contextFromPosition. The first function takes a line/column pair and strives to always return a terminal (even if there's none directly at the given position), while the latter uses a character index and implements the approach exactly as I mentioned in the previous paragraph.

Vim regex matching multiple results on the same line

I'm working on a project where I'm converting an implementation of a binary tree to an AVL tree, so I have a few files that contain lines like:
Tree<int>* p = new Tree<int>(*t);
all over the place. The goal I have in mind is to use a vim regex to turn all instances of the string Tree into the string AVLTree, so the line above would become:
AVLTree<int>* p = new AVLTree<int>(*t);
the regex I tried was :%s/Tree/AVLTree/g, but the result was:
AVLTree<int>* p = new Tree<int>(*t);
I looks to me like when vim finds something to replace on a line it jumps to the next one, so is there a way to match multiple strings on the same line? I realize that this can be accomplished with multiple regex's, so my question is mostly academic.
Credit on this one goes to Marth for pointing this out. My issue was with vim's gdefault. By default it's set to 'off', which means you need the /g tag to make your search global, which is what I wanted. I think mine was set to 'on', which means without the tag the search is global, but with the tag the search is not. I found this chart from :help 'gdefault' helpful:
command 'gdefault' on 'gdefault' off
:s/// subst. all subst. one
:s///g subst. one subst. all
:s///gg subst. all subst. one

Search and retrieve patterns from a list

Let's say I have a list of patterns such like ['AB', ')', '%%', '<.*>'].
I need to search for one of them forward or backward, starting from the cursor position.
Once the first one is found, how do I retrieve its index in the list? I.e, how do I know which one it is?
[EDIT]: the thing is that I actually have two lists of the same size. Once the first match is found in one direction, I'll need to search the corresponding one in the other direction.
PLUS, each pattern is associated with a certain precedence (its index in the list), which I need to retrieve once it is found.
(The overall idea is to build something that would be able to answer this question, with custom delimiters and operators.)
Got it: the searchpos function with the 'p' flag allows you to retrieve the position and the id of the match in for a compound pattern, see :help searchpos.

C++ Xersers removeChildnode and flush leaves an empty line

Env setup :
Using Xersers and DOM Parsers.
Implementation in C++.
OS - SUSE Linux
Problem :
The DOMNode::removeChildNode(DOMNode*) is invoked to remove a specific node (I am speaking of valid node , available deletion. No exception scenario). Later the data is written into using the DOMWriter DOMWriter::writeNode(&targetm,DOMDocument).
a. When I open the file after operation, I see that instead of removing a node, it has been replaced by empty line.
b. If the operations are carried over multiple times, then the xml file will be filled with empty lines. Each add does not use these empty lines, but instead will use a new line, extending the parent node.
I think I am missing some attribute setting, but not able to find it.
Could it be that you remove element nodes, leaving whitespace text nodes around? In terms of text, you're removing starting from the < of the opening tag and up to the > of the closing one.

Difference between content node and document root

I have recently read about XSLT and Xpath. But i came across document root and content node, so many times. Are these are same? Or different?
Correct me if am wrong.
The root node is the node that is the ancestor of all other nodes in the XML document. It is not an element. It has no markup: you cannot see it in a serialized document. It is the parent of the outermost element (and of any siblings that element may have, such as comments or processing instructions). The root node is matched by the XPath expression /.
Confusingly, the outermost element is sometimes called the "root element," and is referred to that way in the XML specification; but in the XSLT specification it is only called the document element. This element is matched by the XPath expression /*.
The context node (if that's what you wanted -- I'm looking at your comment about a confusion) is whatever node the processor considers to be the current node to focus on, when evaluating a particular (piece of an) XPath expression or XSLT instruction, as it occurs in the context of an XSLT stylesheet or other execution environment. See current-node in the XSLT spec. The context node is the meaning of the XPath expression ..