Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click an option in dropdown menu using PHP Selenium Webdriver?

I am using PHP Selenium Webdriver wrapper by Facebook. Can anyone please give me an example of how to click or select an option from a select drop down menu?

I have tried this:

$test = $driver->findElement( WebDriverBy::id('drop1').WebDriverBy::cssSelector("option[value='11']"));
$test->‌​click();

but it errors out:

Message : Object of class WebDriverBy could not be converted to string

like image 496
condo1234 Avatar asked Oct 21 '13 09:10

condo1234


1 Answers

It should be

$test = $driver->findElement( WebDriverBy::id('drop1') )
               ->findElement( WebDriverBy::cssSelector("option[value='11']") )
               ->click();

If you are working on "select" tag, use WebDriverSelect instead.

$select = new WebDriverSelect($driver->findElement(WebDriverBy::id('drop1')));
$select->selectByValue('11');
like image 51
whhone Avatar answered Sep 28 '22 02:09

whhone