Code: Check if the element has focus?
Is there a way to assert that an element (like an input or a link) has keyboard focus? I am using Codeception with Selenium. Couldn't find anything at http://codeception.com/docs/modules/WebDriver
+3
source to share
2 answers
More details on @ sunomad 's answer
Activate Code Sets the module to acceptance.suite.yml
:
modules:
enabled:
# ...
- Asserts
Then use this in your Acceptance test:
$focus = $I->executeJS('return $("#element").is(":focus")');
$I->assertEquals(true, $focus);
Works (via Selenium) with Firefox and Chrome. However, it doesn't work with PhantomJS - see this issue: https://github.com/ariya/phantomjs/issues/10427
+1
source to share