Frage

Please help me!
I don't know how to select deeply nested tag to select the text inside of it.
If someone would please help me by saying, how to do it in a single line with xpath query and please give me an explanation regarding the answer.
Below I have given a html code will anybody explain how to display the Hello world or whatever may be in that tags.

<div>
  <div>
    <div>
      <div>
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>
                    <div class="deep">
                      <span>
                        <strong class="select">Hello world!</strong>
                      </span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
War es hilfreich?

Lösung

I assume since you asked for the text property the node you'd like to match is the strong tag (the only one with content).

If you are guaranteed only one <strong> tag from the document root and the level of nesting is irrelevant, the simplest xpath would be:

//strong/text()

To match via class specifically as well:

//strong[@class="select"]/text()

// will start from the document root, and @ is an attribute match clause.

http://www.b624.net/modelare-software-uml-si-xml/laboratoare-an-3-is/xpath-cheat-sheet

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top