8

Facebook のPHP Selenium Webdriver ラッパーを使用しています。選択ドロップダウンメニューからオプションをクリックまたは選択する方法の例を教えてください。

私はこれを試しました:

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

しかし、それはエラーになります:

メッセージ: クラス WebDriverBy のオブジェクトを文字列に変換できませんでした

4

4 に答える 4

16

そのはず

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

「select」タグを使用している場合は、WebDriverSelect代わりに使用してください。

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

項目をクリックまたは選択しますか? フォローよりも選択した場合: Facebook フレームワーク ヘルパー

次のように動作します:

$selectingContainer = $driver->findElement("ロケータ");

$selection = new WebDriverSelect($selectingContainer);

$selection->selectByVisibleText($text);

"locator" - ドロップダウン メニュー要素のロケータです。

于 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 に答える