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

Selenium select for dropdown doesn't work with duplicate option values #111

Open
splatEric opened this issue Jul 30, 2015 · 1 comment
Open

Comments

@splatEric
Copy link

If a page contains more than one dropdown that contains the same option value, the specificity of the selector is not granular enough to pick the right option. The "element" parameter that gets passed through to the select method is completely ignored by the Selenium component, and it just looks for an option with the provided value.

This works fine when that option value is unique on the page, but otherwise can lead to incorrect behaviour. To resolve this, I've overridden the select method to be the following:

public function select($element, $option)
{
    $this->findByNameOrId($element)->element('css selector', "option[value='{$option}']")->click();
    return $this;
}
@StefanNeuser
Copy link

i fixed it in Laracasts\Integrated\Extensions\Selenium like

´´´
/**
* Select an option from a dropdown.
*
* @param string $option
* @param string $element
* @return static
*/
public function select($option, $element)
{
$this->findByValue($option, "select[name=$element] > option")->click();

    return $this;
}

´´´

And for all Laravel 5.1 Selenium User (with Integrated package) you need to boostrap your Application first like

´´´

webDriver = new WebDriver($host); $capabilities = []; return $this->session = $this->webDriver->session($this->getBrowserName(), $capabilities); } /** * @var \Illuminate\Foundation\Application */ protected $app; /** * Setup the test environment. * * @return void */ public function setUp() { if ( ! $this->app ) { $this->app = $this->createApplication(); } } /** * Creates the application. * * @return \Illuminate\Foundation\Application */ public function createApplication() { $app = require __DIR__ . '/../bootstrap/app.php'; $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); return $app; } ``` } ´´´

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants