8

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

3
  • check if this link can help you ! Commented Oct 21, 2013 at 9:12
  • not 100% sure how that would work for the Facebook wrapper, do you have an example Commented Oct 21, 2013 at 10:30
  • I 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" Commented Oct 21, 2013 at 10:40

4 Answers 4

17

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');
Sign up to request clarification or add additional context in comments.

Comments

5

Try the below code.

$test = $driver->findElement("css selector", 'select[id="drop1"] option[value='11']');
$test->‌​click();

Comments

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.

1 Comment

If I have to select another select list so I have to create new instance for it?
-1

This worked for me, hope it helps someone :)

findElement( WebDriverBy::cssSelector(
                        'div#sku-grid.grid-view table.items thead tr.filters td 
                         select[name="Pro[exception_type]"] option[value="inRetail"]'
                         ));`   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.