开发者

How to simulate a selection from a SELECT control in sfTestBrowser

开发者 https://www.devze.com 2023-03-07 05:50 出处:网络
In a functional test in symfony, sfTestBrowse开发者_如何学JAVAr provides methods click() \"Simulates a click on a link or button.\"

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

精彩评论

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