简体   繁体   English

我如何访问变量按钮:包含类css phpUnit symfony2

[英]how I can access variable button:contains with class css phpUnit symfony2

 <button class="btn btn-lg btn-yellow" type="submit" ng-click="submitForm($event)">

<span class="visible-xs glyphicon glyphicon-search"> </span>

<span class="hidden-xs">Rechercher</span>
</button>

class : the problem : $crawler->selectButton('.btn btn-lg btn-yellow') doesn't exist how I can access this variable ? 类:问题:$ crawler-> selectButton('。btn btn-lg btn-yellow')不存在,如何访问此变量? because I don't have a Id or name 因为我没有编号或名字

  private $client;

protected function setUp()
{
    $client = static::createClient();
    $this->client = $client;
}


    public function testForm()
{

    $crawler = $this->client->request('GET', '/test');
    $form = $crawler->selectButton('.btn btn-lg btn-yellow')->form();

    $form->setValues(
        array(
            'form[search[searchName]]' => 'nom',
            //'form[search]' => 'search'
        )
    );

    $this->client->submit($form);

There are two issues with your current approach: First selectLink() does not work with arbitrary CSS selectors. 当前的方法有两个问题:首先, selectLink()不适用于任意CSS选择器。 Also separating class names with spaces does not mean that the desired element has all class names (your selector would filter for a btn-yellow element inside a btn-lg element inside an element having the class .btn ). 同样用空格分隔类名并不意味着所需的元素具有所有类名(您的选择器将过滤具有.btn类的元素内的btn-lg元素内的btn-yellow元素)。

If you want to filter for an element with multiple classes you would have to do that like this: $crawler->filter('.btn.btn-lg.btn-yellow') 如果要过滤具有多个类的元素,则必须这样做: $crawler->filter('.btn.btn-lg.btn-yellow')

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

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