Search code examples
phptestingseleniumselenium-webdriverhidden-field

Get text from silenium php-webdriver from hidden form value


I am using php-webdriver (facebook) and wait 90 seconds for a webpage where name="mdn" is found by following code. This works well but after this I would like to get the text of name="mdn". The hidden form field has a value but on $number there is no value. Does somebody know whats wrong?

Test.php:

$driver->wait(90, 10000)->until(
    WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(
        WebDriverBy::name('mdn')
    )
);

$number= $driver->findElement(WebDriverBy::name('mdn'))->getText();

Page:

<div  id="main content"  align="center" class="mainCon">
  <div class="mainBG1">
    <table width="900" cellspacing="0" cellpadding="0">
      <tr>
        <td width="650" valign="top">
          <div  class="paddingT20 paddingB20" style="font-family:'Oswald', sans-serif;  font-weight:normal; font-size:35px">xxxxxxx Completed</div>
          <form method="post" action="xxxxxxxxxxxxxxxxxxxxxx" target="_blank">
            <input type="hidden" name="trans_id" value="1234567" />
            <input type="hidden" name="mdn" value="1234567890" />
            <input type="hidden" name="bal" value="" />
            <input type="hidden" name="exp" value="" />
            <input type="hidden" name="note" value="" />
            <table width="40%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td colspan="2" class="dv-R">&nbsp;</td>
              </tr>
                    <tr>
                <td width="40%" class="dv-L">MDN</td>
                <td width="60%" class="dv-R">6142086840</td>
              </tr>
              <tr>
                <td width="32%" class="dv-L">&nbsp;</td>
                <td width="68%" class="dv-R"><input type="image" value="Print"  src="images/xxxxx.png" /></td>
              </tr>
            </table>
            <div class="InfoGr paddingT20 paddingB20"></div><br/> 
                </p>
          </form>   
          <div class="paddingB40"></div>      
        </td>
        <td valign="top" bgcolor="#e2e2e2">&nbsp;</td>
      </tr>
    </table>
  </div>
</div>

Solution

  • You can use getAttribute(), because your page have atrribute value and not text.

    e.g.

    $number= $driver->findElement(WebDriverBy::name('mdn'))->getAttribute('value');