Integrated
Integrated copied to clipboard
Selenium select for dropdown doesn't work with duplicate option values
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;
}
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; } ``` } ´´´