开发者

How to simulate a selection from a SELECT control in sfTestBrowser

In a functional test in symfony, sfTestBrowse开发者_如何学JAVAr provides methods

  • click() "Simulates a click on a link or button."
  • select() "Simulates selecting a checkbox or radiobutton."

and unselect().

But I have not found a way to simulate making a selection from a <select> element.

Does anybody know a way to do this?


This has troubled me too. I'm assuming you just want to set the value for form submission? If you know the value, you can of course just do

$browser->click('Save', array(
    'theselectfield' => 'desired_value'
));

But usually I don't know the value I want posted, because it's from a database-driven select box. So my solution is

$theOption = $browser->getResponseDomCssSelector()->matchAll('select[name*=name_of_select_field] option:contains(TheOptionTextYouWant)')->getNode();

$browser->setField('theselectfield', $theOption->getAttribute('value'));
... or use $browser->click() instead ...

Frustrating because you have to break out of the $browser call chain, in order to use getResponseDomCssSelector(), but I haven't found an easier way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜