Click an option in dropdown menu using PHP Selenium Webdriver?
10,180
Solution 1
Try the below code.
$test = $driver->findElement("css selector", 'select[id="drop1"] option[value='11']');
$test->click();
Solution 2
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');
Solution 3
Do you want click or select item? If select than follow: Facebook framework helper
Works like:
$selectingContainer = $driver->findElement("locator");
$selection = new WebDriverSelect($selectingContainer);
$selection->selectByVisibleText($text);
"locator" - it is locator for dropdown menu element.
Author by
condo1234
Updated on July 28, 2022Comments
-
condo1234 almost 2 years
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
-
HemChe over 10 yearscheck if this link can help you !
-
condo1234 over 10 yearsnot 100% sure how that would work for the Facebook wrapper, do you have an example
-
condo1234 over 10 yearsI 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"
-
-
Sohail Ahmad over 10 yearsIf I have to select another select list so I have to create new instance for it?