Ad

How Can I Get Text On Tags At Selenium By Using Xpath?

I'm trying what autotest with selenium, and i want to scrape texts from multiple tags by using xpath.

that i want, texts html structure looks like this

<div class="roomcard-banner">
    <h2>101</h2>
    <span>text1</span>    
</div>
<div class="roomcard-banner">
    <h2>102</h2>
    <span>text2</span>    
</div>
<div class="roomcard-banner">
    <h2>103</h2>
    <span>text3</span>    
</div>

and i want result like this 101, 102, 103

how can i get i want result by using xpath?

could you show me an example? sorry,,,,

my einglish level is very low,,,, please i will wait for your answer

Ad

Answer

You can use something like this,

$xpath = new DOMXPath($doc);
$n= $xpath->query("/div");
foreach ($n as $node) {
    echo $node->nodeName.' ->'.$node->nodeValue.", ";
}
Ad
source: stackoverflow.com
Ad