XPath – Select first element after some other element

I had to read through your question a couple of times but I think I understand it. What you are interested in is predicates. Predicates allow you to pick nodes based on conditions. For example, you could do: //a[text()=’second dropdown menu’]/following::ul[1]/li/a[text()=’link i want to find’] this would select any anchor with certain text in, find … Read more

Xpath “ends-with” does not work

The ends-with function is part of xpath 2.0 but browsers (you indicate you’re testing with chrome) generally only support 1.0. So you’ll have to implement it yourself with a combination of string-length, substring and equals substring(@id, string-length(@id) – string-length(‘register’) +1) = ‘register’

XQuery [value()]: ‘value()’ requires a singleton (or empty sequence), found operand of type ‘xdt:untypedAtomic *’

A co-worker had tackled a similar problem before. Here is what we came up with. NOT intuitive! insert into PurchaseDetails (Upc, Quantity, PurchaseDate, PurchaseCity, PurchaseState) select pd.value(‘Upc[1]’,’char(11)’), pd.value(‘Quantity[1]’,’int’), pd.value(‘PurchaseDate[1]’,’varchar(7)’), pd.value(‘PurchaseCity[1]’,’varchar(50)’), pd.value(‘PurchaseState[1]’,’char(2)’) from @xmlData.nodes(‘//Database/PurchaseDetails’) as x(Rec) cross apply @xmlData.nodes(‘//Database/PurchaseDetails/PurchaseDetail’) as i(pd)

How do I select only visible elements using XPath?

This should work: .//button[.=’OK’ and not(ancestor::div[contains(@style,’display:none’)]) and not(ancestor::div[contains(@style,’display: none’)])] EDIT: The simpler and more efficient expression below: //div[not(contains(@style,’display:none’))]//button[.=’OK’] does not work properly because every button has at least one div that’s visible in its ancestors.

XPath find all elements with specific child node

Whenever the structure of the XML document is known, it is better to avoid using the // XPath pseudo-operator, as its use can result in big inefficiency (traversal of the whole document tree). Therefore, I recomment this XPath expression for the provided XML document: /*/b[c] This selects any b element that is a child of … Read more

XPath Query: get attribute href from a tag

For the following HTML document: <html> <body> <a href=”http://www.example.com”>Example</a> <a href=”http://www.stackoverflow.com”>SO</a> </body> </html> The xpath query /html/body//a/@href (or simply //a/@href) will return: http://www.example.com http://www.stackoverflow.com To select a specific instance use /html/body//a[N]/@href, $ /html/body//a[2]/@href http://www.stackoverflow.com To test for strings contained in the attribute and return the attribute itself place the check on the tag not on … Read more

Select iframe using Python + Selenium

This worked for me with Python (v. 2.7), webdriver & Selenium when testing with iframes and trying to insert data within an iframe: self.driver = webdriver.Firefox() ## Give time for iframe to load ## time.sleep(3) ## You have to switch to the iframe like so: ## driver.switch_to.frame(driver.find_element_by_tag_name(“iframe”)) ## Insert text via xpath ## elem = … Read more

Converting JSON to XML in Java

Use the (excellent) JSON-Java library from json.org then JSONObject json = new JSONObject(str); String xml = XML.toString(json); toString can take a second argument to provide the name of the XML root node. This library is also able to convert XML to JSON using XML.toJSONObject(java.lang.String string) Check the Javadoc Link to the the github repository POM … Read more

What is the difference between name() and local-name()?

With the XML being <x:html xmlns:x=”http://www.w3.org/1999/xhtml”/> the stylesheet <xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” version=”1.0″> <xsl:output indent=”yes”/> <xsl:template match=”*”> <local-name><xsl:value-of select=”local-name()”/></local-name> <name><xsl:value-of select=”name()”/></name> </xsl:template> </xsl:stylesheet> outputs <local-name>html</local-name> <name>x:html</name> So the local-name() result is without any prefix, the name() result might include a prefix. In your sample with a default namespace declaration no prefix is present, therefore name() and local-name() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)