BrotherShamus
BrotherShamus

Reputation: 63

Select form input without id in behat

I need to write a custom function to populate an email input field with a unique email address. But the page has dynamically-generated IDs, so I can't just use $page->find() to easily grab the elements. How do I grab the input element by its name?

public function iFillInUniqueEmail($arg1)
{
    $page = $this->getSession()->getPage();

    $element = $page->find('css', $arg1);

    if (null === $element) {
      throw new InvalidArgumentException(sprintf('Could not evaluate CSS selector: "%s"', $arg1));
    }

    $date = date('YmdHis');
    $email = "test" . $date . "@test.com";

    $element->setValue($email);
}

Upvotes: 0

Views: 272

Answers (1)

u_mulder
u_mulder

Reputation: 54796

You can find element by name attribute like this:

$el = $page->find('css', 'input[name="input_name_goes_here"]');

Upvotes: 1

Related Questions