Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
ability to choose select option by text (closes minkphp#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Sep 29, 2011
1 parent b36ef63 commit 173c49d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/Behat/Mink/Element/NodeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Behat\Mink\Session,
Behat\Mink\Driver\DriverInterface,
Behat\Mink\Element\ElementInterface;
Behat\Mink\Element\ElementInterface,
Behat\Mink\Exception\ElementNotFoundException;

/*
* This file is part of the Behat\Mink.
Expand Down Expand Up @@ -161,7 +162,21 @@ public function isChecked()
*/
public function selectOption($option)
{
$this->getSession()->getDriver()->selectOption($this->getXpath(), $option);
if ('select' !== $this->getTagName()) {
$this->getSession()->getDriver()->selectOption($this->getXpath(), $option);

return;
}

$opt = $this->find('named', array('option', $option));

if (null === $opt) {
throw new ElementNotFoundException(
$this->getSession(), 'select option', 'value|text', $option
);
}

$this->getSession()->getDriver()->selectOption($this->getXpath(), $opt->getValue());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/Mink/Driver/GeneralDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function testAdvancedForm()
$maillist->uncheck();
$this->assertFalse($maillist->isChecked());

$select->selectOption('10');
$select->selectOption('ten');
$this->assertEquals('10', $select->getValue());

$sex->selectOption('m');
Expand Down

0 comments on commit 173c49d

Please sign in to comment.