Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot focus web element to send keys

I have a set of tests where I need to login and then perform a search. My Application is an Angular JS and I am suing protractor. In fact, my tests where working fine until I receive a new kit of my application and all my tests are failing at this point :

 element(by.id('mainGlobalSearchBtn')).sendKeys('a');

Here is my console output :

1) change number of items displayed by page should display 20 items per page

Message      : UnknownError: unknown error: cannot focus element
(Session info: chrome = 33.0.1750.117)
(Driver info : chromedriver = 2.8.241075, platform = Windows NT 6.1 SP1 x86_64)
(WARNING     : The server did not provide any stacktrace information)

Command duration or timeout: 70 milliseconds
Build info: version: '2.39.0',
revision: 'ff23eac',
time: '2013-12-16 16:11:15'
System info: host: 'vmstmselhub',
ip: '203.0.113.1',
os.name: 'Windows 7',
os.a
rch: 'amd64',
os.version: '6.1',
java.version: '1.7.0_40'
Session ID: aad8a0d0ed00088c3bbfc80c546c75ff
Driver info: org.openqa.selenium.chrome.ChromeDriver

Capabilities[{
    platform = XP, 
    acceptSslCerts = true, 
    javascriptEnabled = true, 
    browserName = chrome, 
    chrome = {
        userDataDir = C:\Users\orsyp\AppData\Local\Temp\scoped_dir3592_13478
    }, 
    rotatable = false, 
    locationContextEnabled = true, 
    version = 33.0.1750.117, t
    akesHeapSnapshot = true, 
    cssSelectorsEnabled = true, 
    databaseEnabled = false, 
    handlesAlerts = true, 
    browserConnectionEnabled = false, 
    nativeEvents = true, 
    webStorageEnabled = true, 
    applicationCacheEnabled = false, 
    takesScreenshot = true
}]


Stacktrace   : 

UnknownError : unknown error: cannot focus element
(Session info: chrome = 33.0.1750.117)
(Driver info : chromedriver = 2.8.241075, platform = Windows NT 6.1 SP1 x86_64)
(WARNING     : The server did not provide any stacktrace information)

Command duration or timeout: 70 milliseconds
Build info: version: '2.39.0',
revision: 'ff23eac',
time: '2013-12-16 16:11:15'
System info: host: 'vmstmselhub',
ip: '203.0.113.1',
os.name: 'Windows 7',
os.a
rch: 'amd64',
os.version: '6.1',
java.version: '1.7.0_40'
Session ID: aad8a0d0ed00088c3bbfc80c546c75ff
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities[{
    platform = XP, 
    acceptSslCerts = true, 
    javascriptEnabled = true, 
    browserName = chrome, 
    chrome = {
        userDataDir = C:\Users\orsyp\AppData\Local\Temp\scoped_dir3592_13478
    }, 
    rotatable = false, 
    locationContextEnabled = true, 
    version = 33.0.1750.117, 
    takesHeapSnapshot = true, 
    cssSelectorsEnabled = true, 
    databaseEnabled = false, 
    handlesAlerts = true, 
    browserConnectionEnabled = false, 
    nativeEvents = true, 
    webStorageEnabled = true, 
    applicationCacheEnabled = false, 
    takesScreenshot = true
}]
at new bot.Error(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js: 109: 18
)
at Object.bot.response.checkResponse(
    C:\node_modules\protractor\node_module s\selenium-webdriver\lib\atoms\response.js: 106: 9
)
at C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js: 276: 20
at C:\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js: 1178: 15
at webdriver.promise.ControlFlow.runInNewFrame_(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js: 1445: 20
)
at notify(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\we bdriver\promise.js: 328: 12
)
at notifyAll(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js: 297: 7
)
at fulfill(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js: 402: 7
)
at C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js: 1312: 10
at C:\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js: 1178: 15 

=== = async task === =

WebElement.sendKeys([object Object])
at webdriver.WebDriver.schedule(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js: 267: 15
)
at webdriver.WebElement.schedule_(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js: 1591: 23
)
at webdriver.WebElement.sendKeys(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js: 1752: 15
)
at element.(anonymous function)[as sendKeys](
    C:\node_modules\protractor\lib\protractor.js: 440: 32
)
at C:\node_modules\protractor\lib\protractor.js: 89: 34
at C:\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js: 1178: 15
at webdriver.promise.ControlFlow.runInNewFrame_(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js: 1445: 20
)
at notify(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js: 328: 12
)
at notifyAll(
    C:\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js: 297: 7
) 

=== = async task === =
at null. < anonymous > (
    C:\node_modules\protractor\jasminewd\index.js: 53: 12
)
at null. < anonymous > (
    C:\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js: 45: 37
)
at jasmine.Block.execute(
    C:\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js: 1168: 17
)
at jasmine.Queue.next_(
    C:\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js: 2200: 31
)
at null._onTimeout(
    C:\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js: 2190: 18
)
at Timer.listOnTimeout[as ontimeout](
    timers.js: 110: 15
)


Finished in 8.45 seconds
1 test, 1 assertion, 1 failure

I would add that protractor is not able to click/enter text in any of my web element after logging in.

Here is my search form HTML :

<form class="ng-pristine ng-valid" id="mainSearchGroup" name="mainSearchGroup">
    <div id="mainSearch">
        <input class="ng-pristine ng-valid" id="mainGlobalSearch" name=
    "mainGlobalSearch" placeholder="Schedule workflows, name..." type=
    "text">

        <div id="mainSearchIn" style="background-image: url(" title=
    "Filter by...">
        <div class="word-ellipsis ng-binding" id="mainSearchInText">
            All
        </div>

        <div id="mainSearchInRightGrayBorder"></div>

        <div id="mainSearchInBox" style=""></div>
    </div>

    <div class="ng-binding" id="mainGlobalSearchBtn">
        <div class="clear"></div>
      </div>
     </div>
</form>
like image 392
Ziwdigforbugs Avatar asked Feb 24 '14 14:02

Ziwdigforbugs


Video Answer


2 Answers

I had great success using this:

Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.sendKeys("Some Name");
actions.build().perform();

Found here: http://grokbase.com/t/gg/selenium-users/142jj2483b/chromedriver-error-cannot-focus-element

This solution also works for C# since the same classes and methods are present in that API.

like image 106
nath Avatar answered Oct 23 '22 14:10

nath


If it helps the next person, I has to .click() inside the field before sending keys.

like image 27
madz Avatar answered Oct 23 '22 15:10

madz