Identify elements with xPath

3

I wanted to identify the following element on a page:

<input name="ctl00$ContentPlaceHolder1$txtData" type="text" value="19/01/2015" id="ctl00_ContentPlaceHolder1_txtData" style="font-size:110%;font-weight:bold;width:120px;" />

I'm using the following query to find the element:

$node = $xpath->query("//input[@id='ctl00_ContentPlaceHolder1_txtData']");
Is the query correct?

  • What is the best way to get value of this input ?

  • asked by anonymous 19.01.2015 / 23:16

    1 answer

    2

    To get the value it is necessary to put @value at the end of query , thus:

    $node = $xpath->query("//input[@id='ctl00_ContentPlaceHolder1_txtData']/@value");
    

    p>
    $node = $xpath->query("//input[@id='ctl00_ContentPlaceHolder1_txtData']/@value");
    echo $node->item(0)->value;
    

    xPathTest Demo

        
    19.01.2015 / 23:47