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

4

4 回答 4

16

它应该是

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

如果您正在处理“选择”标签,请WebDriverSelect改用。

$select = new WebDriverSelect($driver->findElement(WebDriverBy::id('drop1')));
$select->selectByValue('11');
于 2013-10-23T19:11:58.267 回答
5

试试下面的代码。

$test = $driver->findElement("css selector", 'select[id="drop1"] option[value='11']');
$test->‌​click();
于 2013-10-21T11:40:29.793 回答
3

您要单击还是选择项目?如果选择比关注:Facebook 框架助手

像这样工作:

$selectingContainer = $driver->findElement("locator");

$selection = new WebDriverSelect($selectingContainer);

$selection->selectByVisibleText($text);

“定位器” - 它是下拉菜单元素的定位器。

于 2013-10-21T12:56:52.273 回答
-1

这对我有用,希望对某人有所帮助:)

findElement( WebDriverBy::cssSelector(
                        'div#sku-grid.grid-view table.items thead tr.filters td 
                         select[name="Pro[exception_type]"] option[value="inRetail"]'
                         ));`   
于 2014-02-25T13:59:40.127 回答