Behat works fine but PhantomJS fails on dropdown menu when trying to click

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 09:06:33

问题


Gherkin below works fine with behat but when I use PhantomJS I get error on When I follow "Profile" line below:

Note: The element is a dropdown menu from bootstrap so it toggles after click.

Error:

Exception thrown by (//html/.//a[./@href][(((./@id = 'Profile' or contains(normalize-space(string(.)), 'Profile')) or contains(./@title, 'Profile') or contains(./@rel, 'Profile')) or .//img[contains(./@alt, 'Profile')])] | .//*[./@role = 'link'][((./@id = 'Profile' or contains(./@value, 'Profile')) or contains(./@title, 'Profile') or contains(normalize-space(string(.)), 'Profile'))])[1]
{"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"27","Content-Type":"application/json; charset=utf-8","Host":"localhost:5140","User-Agent":"Apache-HttpClient/4.3.4 (java 1.5)"},"httpVersion":"1.1","method":"POST","post":"{\"id\":\":wdc:1412065547042\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/5b7c0830-487b-11e4-adc0-a162f25e4a98/element/%3Awdc%3A1412065547042/click"}}

Gherkin:

When I follow "Profile"
And I follow "Edit"

HTML:

<ul class="nav navbar-nav navbar-right">
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Profile <span class="caret"></span></a>
        <ul class="dropdown-menu" role="menu">
            <li><a href="#">Show</a></li>
            <li><a href="#">Edit</a></li>
        </ul>
    </li>
</ul>

回答1:


I've discovered why and solved with a small fix as shown below.

When using Bootstrap, the menus get squashed down and only an icon appears to represent the same menu which is the normal behaviour for responsive design. All fine for now but when PhantomJS is run, it cannot find the text it is looking for. e.g. "Profile" menu in my case.

Original state of the menu, which always works fine:

After squashed down version which causes PhantomJS to fail:

SOLUTION:

Just set the window size to something bigger so that the menu doesn't get squashed down when testing. You can change the screen size from 1024X768 to something else as you wish.

#symfony/src/Site/CommonBundle/Features/Context/FeatureContext.php

/**
 * @BeforeStep
 */
public function beforeStep()
{
    $this->getSession()->resizeWindow(1024, 768, 'current');
}


来源:https://stackoverflow.com/questions/26116316/behat-works-fine-but-phantomjs-fails-on-dropdown-menu-when-trying-to-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!