简体   繁体   English

使用PHP Selenium Webdriver单击下拉菜单中的选项?

[英]Click an option in dropdown menu using PHP Selenium Webdriver?

I am using PHP Selenium Webdriver wrapper by Facebook . 我正在使用Facebook的 PHP Selenium Webdriver包装器。 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 消息 :类WebDriverBy的对象无法转换为字符串

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”标记,请改用WebDriverSelect

$select = new WebDriverSelect($driver->findElement(WebDriverBy::id('drop1')));
$select->selectByValue('11');

Try the below code. 请尝试以下代码。

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

Do you want click or select item? 您想要点击还是选择项目? If select than follow: Facebook framework helper 如果选择比以下: Facebook框架助手

Works like: 像:

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

$selection = new WebDriverSelect($selectingContainer); $ selection = new WebDriverSelect($ selectingContainer);

$selection->selectByVisibleText($text); $选择 - > selectByVisibleText($文本);

"locator" - it is locator for dropdown menu element. “locator” - 它是下拉菜单元素的定位器。

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"]'
                         ));`   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM