Skip to content

Commit

Permalink
selectOption - select option from different selector (#3248)
Browse files Browse the repository at this point in the history
* Fix issue #3246

* Add test testSelectInvalidOptionForSecondSelectFails

* Add html form
  • Loading branch information
eXorus authored and DavertMik committed Jun 21, 2016
1 parent f6d73df commit 3f4521e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Codeception/Module/WebDriver.php
Expand Up @@ -1101,7 +1101,7 @@ public function selectOption($select, $option)
// partially matching
foreach ($option as $opt) {
try {
$optElement = $el->findElement(WebDriverBy::xpath('//option [contains (., "' . $opt . '")]'));
$optElement = $el->findElement(WebDriverBy::xpath('.//option [contains (., "' . $opt . '")]'));
$matched = true;
if (!$optElement->isSelected()) {
$optElement->click();
Expand Down
14 changes: 14 additions & 0 deletions tests/data/app/view/form/select_second.php
@@ -0,0 +1,14 @@
<html>
<body>
<form action="/form/complex" method="POST">
<select id="select1">
<option value="select1_value1">Value1</option>
<option value="select1_value2">Value2</option>
</select>
<select id="select2">
<option value="select2_value1">Value1</option>
</select>
<input type="submit" value="Submit" />
</form>
</body>
</html>
7 changes: 7 additions & 0 deletions tests/web/WebDriverTest.php
Expand Up @@ -70,6 +70,13 @@ public function testSelectByCss()
$this->assertEquals('adult', $form['age']);
}

public function testSelectInvalidOptionForSecondSelectFails()
{
$this->shouldFail();
$this->module->amOnPage('/form/select_second');
$this->module->selectOption('#select2', 'Value2');
}

public function testSeeInPopup()
{
$this->notForPhantomJS();
Expand Down

0 comments on commit 3f4521e

Please sign in to comment.