Codeception / Codeception/Codeception

Bug with selectOption(): Doesn't select radiobutton by its label

Open
#4,516 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
4.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I'm trying to use `selectOption()` with `array('text' => 'Windows')` as its second argument, as shown here:
http://codeception.com/docs/modules/WebDriver#selectOption

Here's a sample HTML:

```html



One
Two

```

And this code is not working:
```php
$I->selectOption('input[name="myfield"]', ['text'=>'Two']);
```

When I try it in an acceptance test, I get:
```bash
[PHPUnit\Framework\Exception] Array to string conversion
```

And when I try it in a functional test, I get:
```bash
[InvalidArgumentException] Input "myfield" cannot take "Two" as a value (possible values: 1, 2).
```

I guess the problem comes from this line in `InnerBrowser.php`: https://github.com/Codeception/Codeception/blob/2.3/src/Codeception/Lib/InnerBrowser.php#L1097
```php
$options = $field->filterXPath(sprintf('//option[text()=normalize-space("%s")]|//input[@type="radio" and @value=normalize-space("%s")]', $option, $option));
```
The second part of the XPath expression searches for inputs with the given **value** (`@value`), not for inputs with the given text as **label**.

* Codeception version: 2.3.5
* PHP Version: 7.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.