Get all immediate children and nothing deeper
(“*”) gives all the child elements of the context node. So use: body.findElement(By.xpath(“*”));
(“*”) gives all the child elements of the context node. So use: body.findElement(By.xpath(“*”));
HTML <div id=’a’> <div> <a class=”click”>abc</a> </div> </div> You could use the XPATH as : //div[@id=’a’]//a[@class=”click”] output <a class=”click”>abc</a> That said your Python code should be as : driver.find_element_by_xpath(“//div[@id=’a’]//a[@class=”click”]”)
Use the following: (//dl)[1] The parentheses are significant. You want the first node that results from //dl (not the set of dl elements that are the first child of their parent (which is what //dl[1] (no parens) returns)). This is easier to see when one realizes that // is shorthand for (i.e. expands fully to) … Read more
[Update] XMLQuire was originally recommended in this answer. It was a free XML editor for Windows with the SketchPath XPath Editor built in for XPath testing. XMLQuire has not been maintained for a few years and has now been retired. For XPath experimentation etc. XMLQuire’s author now recommends the XPath Notebook extension for Visual Studio … Read more
Use name(). (Find docs for newer versions of the XPath language here.) Here are modified versions of your example: Works in XPath 2.0+ only: //element/*[@id=’elid’]/name() Works in XPath 1.0 and 2.0+*: name(//element/*[@id=’elid’]) *If using 2.0+, the expression //element/*[@id=’elid’] must only return one element. Otherwise you’ll get an error like A sequence of more than one … Read more
Attributes of literal result elements support the attribute value template syntax, using {}: <Party role=”{some/xpath/path}”>
I don’t see why you can’t use this: //table[@id=’foo’]/tr|//table[@id=’foo’]/tbody/tr If you want one expression without node set union: //tr[(.|parent::tbody)[1]/parent::table[@id=’foo’]]
see http://www.w3.org/TR/xpath#path-abbrev // is just an abbreviation for the descendant:: axis Edit To quote: //para is short for /descendant-or-self::node()/child::para That is, it refers to all para which are a child of the context node or any node descended from the context node. As far as I can tell that translates into any descendant para of … Read more
To get the string value of div use: string(/div) This is the concatenation of all text nodes that are descendents of the (top) div element. To select all text node descendents of div use: /div//text() To get only the text nodes that are direct children of div use: /div/text() Finally, get the first (and hopefully … Read more
Try using the .value function instead of .query: SELECT xmlCol.value(‘(/container/param[@name=”paramB”]/@value)[1]’, ‘varchar(50)’) FROM LogTable The XPath expression could potentially return a list of nodes, therefore you need to add a [1] to that potential list to tell SQL Server to use the first of those entries (and yes – that list is 1-based – not 0-based). … Read more