Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectOption - select option from different selector #3246

Closed
eXorus opened this issue Jun 20, 2016 · 2 comments
Closed

selectOption - select option from different selector #3246

eXorus opened this issue Jun 20, 2016 · 2 comments

Comments

@eXorus
Copy link
Member

@eXorus eXorus commented Jun 20, 2016

Hello,

Module : WebDriver
Version : 2.2.1
Browser : Firefox

<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>
$I->selectOption('#select2', 'Value2');

Actual behaviour
The value "Value2" in field "#select1" is selected

Expected behaviour
Failed to select the value "Value2" because it is not in "#select2" field.

@eXorus
Copy link
Member Author

@eXorus eXorus commented Jun 20, 2016

The issue is here in Module/WebDriver.php:selectOption() :

foreach ($option as $opt) {
    try {
        $optElement = $el->findElement(WebDriverBy::xpath('//option [contains (., "' . $opt . '")]'));
        $matched = true;
        if (!$optElement->isSelected()) {
        $optElement->click();
    }
    } catch (NoSuchElementException $e) {
        // exception treated at the end
    }
}

SelectOption doesn't care about the selector it take only the value to do the selection.

@raistlin
Copy link
Member

@raistlin raistlin commented Jun 20, 2016

@eXorus Please add some tests on your branch and submit a pull request.

DavertMik added a commit that referenced this issue Jun 21, 2016
* Fix issue #3246

* Add test testSelectInvalidOptionForSecondSelectFails

* Add html form
@eXorus eXorus closed this Jun 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.