Html xpath来查找特定节点下面的文本框,该节点又包含特定的子节点
我费了好大劲才为这本书写了一个标题 下面是我正在解析的示例Html xpath来查找特定节点下面的文本框,该节点又包含特定的子节点,html,xpath,Html,Xpath,我费了好大劲才为这本书写了一个标题 下面是我正在解析的示例HTML,为了简洁起见,将其部分截断,但希望有人能够理解我在寻找什么 我希望在示例代码的最底部识别输入。 我不能使用ID,因为它不断变化。i、 e.id=“id\u mstr111\u txt” 让我用英语尽可能地描述一下我想达到的目的: 查找输入 …在具有作为后代的DIV的class=“mstrPromptQuestion”下 。。。。。。spanclass=“mstrpromptQuestionTitlePartitle”>摘要期间
HTML
,为了简洁起见,将其部分截断,但希望有人能够理解我在寻找什么
我希望在示例代码的最底部识别输入。
我不能使用ID
,因为它不断变化。i、 e.id=“id\u mstr111\u txt”
让我用英语尽可能地描述一下我想达到的目的:
查找输入
…在具有作为后代的DIV
的class=“mstrPromptQuestion”
下
。。。。。。spanclass=“mstrpromptQuestionTitlePartitle”>摘要期间
或者用另一种方式写:
给定一个包含深度嵌入子节点的DIV
和class=“mstrPromptQuestion”
:spanclass=“mstrpromptquestiblettitlebattle”>抽象时段
查找输入
(不使用ID
,因为数字随每次构建而变化)
我不确定使用XPath 2.0
和没有jquery
——只使用基本的XPath
函数是否可以做到这一点
2.
抽象时期**
(必选)
对于以英语描述的:
//div[@class='mstrPromptQuestion'][.//span[@class='mstrPromptQuestionTitleBarTitle']]//input[contains(@id, '_txt')]
结果是:
//div[@class='mstrPromptQuestion'][.//span[@class='mstrPromptQuestionTitleBarTitle'][contains(text(), 'Abstracted Period')]]//input[contains(@id, '_txt')]
(//div[@class='mstrPromptQuestion']//input)[last()]
//div[@class='mstrPromptQuestion'][.//span[@class='mstrpromptQuestionTitlePartitle'][contains(text(),'Abstracted Period')]]//input[contains(@id,'.-txt')]
如果您确定这是div
中的最后一个输入
,您可以执行以下操作:
//div[@class='mstrPromptQuestion'][.//span[@class='mstrPromptQuestionTitleBarTitle'][contains(text(), 'Abstracted Period')]]//input[contains(@id, '_txt')]
(//div[@class='mstrPromptQuestion']//input)[last()]
或者类似于:
(//div[@class='mstrPromptQuestion' and .//span[@class='mstrPromptQuestionTitleBarTitle']='Abstracted Period']//input)[last()]
如果mstrpromptQuestionTitlePartitle
很重要。我试过这个,它似乎起作用了//div[@class='mstrPromptQuestion'和//span[@class='mstrpromptQuestionTitlePartitle'和text()='Abstracted Period']//输入