Identify elements with xPath

Asked

Viewed 720 times

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 locate the element:

$node = $xpath->query("//input[@id='ctl00_ContentPlaceHolder1_txtData']");
  1. To query is correct?

  2. What is the best way to achieve value that input?

1 answer

2


To catch the value it is necessary to put @value at the end of query, being like this:

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

Like the xpath does not return strings, but we(nodes), to get the value of Node can be done:

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

xPathTest Demo

  • Thanks, but when I put the "->value" it gives this error:"Notice: Undefined Property: Domnodelist::$value in C: xampp htdocs site test.php on line 51" you know what it might be?

  • You keep saying there’s no such function.

  • It worked, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.