xpath

What is the purpose of normalize-space()?

人盡茶涼 提交于 2021-01-27 14:20:48
问题 I don't understand very well the purpose of normalize-space() . I think it's very useful. In fact, I always use it when I am doing tests, but I am not sure the principal purpose. For example, in these two cases, what are the differences? What is the advantage of using it? Example 1 WebElement seleccionLabelCabecera = findBy(xpath("(//div[contains(normalize-space(@class), 'windowViewMode-maximized active')"] Example 2 WebElement seleccionLabelCabecera = findBy(xpath("(//div[@class,

How to select namespace value via XPath

你。 提交于 2021-01-27 14:20:36
问题 I'm trying to get the xmlns:attr attribute value from this XML using XPath. I can't seem to get it. <a:b xmlns:attr="value"> </a:b> This is from the root node. I've tried just about every combination, but I can't seem to find anything that works. 回答1: Setting aside the distraction of the undeclared a: namespace, let's instead use this example: <b xmlns:attr="value"/> Note : Your name choice of attr belies the fact that in the above XML, attr is not an attribute but rather is a namespace

XPath difference between child::* and child::node()

ぐ巨炮叔叔 提交于 2021-01-27 13:21:40
问题 Is there a difference between the following two xpath expressions? child::* child::node() I tried both expressions on this playground page and got the same result. W3schools says child::* Selects all element children of the current node child::node() Selects all children of the current node but I do not get the difference. 回答1: Both child::* and child::node() refer to the children of the current node, so the difference is really in the difference between that of an element and a node . An

How to check a node contains empty string or space or null in xpath?

烂漫一生 提交于 2021-01-27 06:50:06
问题 I want to check using xpath an node in the xml contains empty string/spaces. What is the xpath expression i need to use? eg: <p:insert_acc_data_file xmlns:p="http://ws.wso2.org/dataservice"> <p:Id>123</p:Id> <p:Name></p:pName> </p:insert_acc_data_file> How to check the Name node is empty or containing space values? 回答1: By checking if a node is empty I guess you mean has no child element (text or node) . Checking if a node contains only space values can be done using normalize-space()

How to check a node contains empty string or space or null in xpath?

冷暖自知 提交于 2021-01-27 06:44:55
问题 I want to check using xpath an node in the xml contains empty string/spaces. What is the xpath expression i need to use? eg: <p:insert_acc_data_file xmlns:p="http://ws.wso2.org/dataservice"> <p:Id>123</p:Id> <p:Name></p:pName> </p:insert_acc_data_file> How to check the Name node is empty or containing space values? 回答1: By checking if a node is empty I guess you mean has no child element (text or node) . Checking if a node contains only space values can be done using normalize-space()

Python Xpath: lxml.etree.XPathEvalError: Invalid predicate

主宰稳场 提交于 2021-01-26 09:19:07
问题 I'm trying to learn how to scrape web pages and in the tutorial I'm using the code below is throwing this error: lxml.etree.XPathEvalError: Invalid predicate The website I'm querying is (don't judge me, it was the one used in the training vid :/ ): https://itunes.apple.com/us/app/candy-crush-saga/id553834731 The xpath string that causes the error is here: links = tree.xpath('//div[@class="center-stack"//*/a[@class="name"]/@href') I'm using the LXML and requests libraries. If you need any

Python Xpath: lxml.etree.XPathEvalError: Invalid predicate

醉酒当歌 提交于 2021-01-26 09:17:01
问题 I'm trying to learn how to scrape web pages and in the tutorial I'm using the code below is throwing this error: lxml.etree.XPathEvalError: Invalid predicate The website I'm querying is (don't judge me, it was the one used in the training vid :/ ): https://itunes.apple.com/us/app/candy-crush-saga/id553834731 The xpath string that causes the error is here: links = tree.xpath('//div[@class="center-stack"//*/a[@class="name"]/@href') I'm using the LXML and requests libraries. If you need any

xpath lowercase - Is there xpath function to do this?

做~自己de王妃 提交于 2021-01-21 08:11:41
问题 For example, for the xml below <REPORT ID="TimekeeperListEdited" BoundId="Timekeeper" BoundType="ReportObject" /> How to match the first record with xpath like //*[@BoundId='TimeKeeper'] . Is there xpath function to do this? 回答1: If you are using XPath 2.0 , you can use the lower-case() function: //*[lower-case(@BoundId) = 'timekeeper'] In case your use is restricted to XPath 1.0 , you can convert cases with the translate() function which replaces each character in your string (first argument

Select a node with XPath whose child node contains a specific inner text

北战南征 提交于 2021-01-21 03:56:25
问题 Given the following XML: <root> <li><span>abcText1cba</span></li> <li><span>abcText2cba</span></li> </root> I want to select all li elements having a span child node containing an inner text of Text1 - using an XPath. I started off with /root/li[span] and then tried to further check with: /root/li[span[contains(text(), 'Text1')]] However, this does not return any nodes. I fail to see why, can somebody help me out? 回答1: Just for readers. The xpath is correct. OP: Perhaps xpath parser didnt

Select a node with XPath whose child node contains a specific inner text

痞子三分冷 提交于 2021-01-21 03:55:01
问题 Given the following XML: <root> <li><span>abcText1cba</span></li> <li><span>abcText2cba</span></li> </root> I want to select all li elements having a span child node containing an inner text of Text1 - using an XPath. I started off with /root/li[span] and then tried to further check with: /root/li[span[contains(text(), 'Text1')]] However, this does not return any nodes. I fail to see why, can somebody help me out? 回答1: Just for readers. The xpath is correct. OP: Perhaps xpath parser didnt