I've been working in BDD through Behat|Mink.
However I'm failing in finding an input (field) with an ID or Name if they aren't complete.
I intended to do something like:
$field = $this->getSession()->getPage()->findField( "*first_name*" );
where the '*' meant that can be any piece of string there.
The problem is that i have a case where I can't know for sure the complete ID cause:
id="<random-string>_<actual-field-name>_<random-number>"
Any idea how can I do this?
What have I tried
- get it through label (for some reasons there are some labels that dont have 'for' attribute and sometimes the name is a sentence and not an simple name)
- get it through css/classes (to many variables)
Edit:
I've created a php function to read the attribute and return the value of the intended attribute.
/**
*
* @param string $haystack The complete html
* @param string $needle The string with the part of the attribute value
* @param string $tag The tag of where the attribute should belong
* @param string $attr The attribute to ifnd
* @return string
*/
protected function findCompleteAttribute( $haystack, $needle, $tag = null, $attr = 'id' )
However, in cases that there is another fields (ex: hidden login form) and the needle is also in those inputs, it will get them if they're first.
So I need to specify the form, however, once more, there I haven't a way to find a form through name:
$field = $this->getSession()->getPage()->find( 'named', array( 'form', $formName ) );