Getting error as unable to sendkeys to testobject because unable to focus on element

There is textbox who is used for filtering records and also there is button whose name is also ‘Search’. When I used sendkeys keyword on textbox it works fine but when I click on Search button page loading screen comes. To handle this I have used wait for page load and wait for element is visible = Textbox but I received errors as follows:-

[Test Cases/Test Cases/Manage Connections/TC-MC-011 Verify that user is able to filter buyers or supplier FAILED because (of) Unable to send keys ‘WubsAuto’ to object ‘Object Repository/Manage Connections Section/Search Buyers_Suppliers Page/textbox_Search’ (Root cause: org.openqa.selenium.WebDriverException: unknown error: cannot focus element

(Session info: chrome=63.0.3239.132)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘WKSWUPUN0136’, ip: ‘192.168.0.102’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_102’
Driver info: com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver
Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}
Session ID: 1e317eafb0c2e874cd9c8ad8b3a59d96)

Test Cases/Test Cases/Manage Connections/TC-MC-011 Verify that user is able to filter buyers or supplier.run:50]

When I used hardcoded delay of 5 seconds after page loads it successfully send keys to textbox but as a good coding standards I dont want to use hardcoded delay. Can you please guide me how can I avoid above error and successfully send keys from my excel sheet to text box without using delay keyword.

2 Likes

I have same promlem woth uploads keys, a can’t upload file because: (Root cause: org.openqa.selenium.WebDriverException: unknown error: cannot focus element

Does any body know how to solve such problem?

Screenshot_120.png

I am having the same problem. Has any of the above got any solutions?
Rostyslav Biliaiev said:

Rostyslav Biliaiev said:

I have same promlem woth uploads keys, a can’t upload file because: (Root cause: org.openqa.selenium.WebDriverException: unknown error: cannot focus element

Does any body know how to solve such problem?

Murtaja Arifhusen Kadiyani said:

There is textbox who is used for filtering records and also there is button whose name is also ‘Search’. When I used sendkeys keyword on textbox it works fine but when I click on Search button page loading screen comes. To handle this I have used wait for page load and wait for element is visible = Textbox but I received errors as follows:-

[Test Cases/Test Cases/Manage Connections/TC-MC-011 Verify that user is able to filter buyers or supplier FAILED because (of) Unable to send keys ‘WubsAuto’ to object ‘Object Repository/Manage Connections Section/Search Buyers_Suppliers Page/textbox_Search’ (Root cause: org.openqa.selenium.WebDriverException: unknown error: cannot focus element

(Session info: chrome=63.0.3239.132)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘WKSWUPUN0136’, ip: ‘192.168.0.102’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_102’
Driver info: com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver
Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}
Session ID: 1e317eafb0c2e874cd9c8ad8b3a59d96)

Test Cases/Test Cases/Manage Connections/TC-MC-011 Verify that user is able to filter buyers or supplier.run:50]

When I used hardcoded delay of 5 seconds after page loads it successfully send keys to textbox but as a good coding standards I dont want to use hardcoded delay. Can you please guide me how can I avoid above error and successfully send keys from my excel sheet to text box without using delay keyword.

I am not certain it will help, but did you try…

https://docs.katalon.com/display/KD/[WebUI]+Wait+For+Element+Clickable

The same problem, Does anybody know the solution?

having same problem? Anyone got any solution?

I have same problem? Does anybody know how to fix it? Thanks!

All of you, please read this and respond accordingly:

You should also start a new topic since the original posting is old and the OP has not responded since.

So to resolve ‘cannot focus on an element’ based on this approach: https://grokbase.com/t/gg/selenium-users/142jj2483b/chromedriver-error-cannot-focus-element, you will need to use the following script ( replace ‘Send Keys’ keyword with it):

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.interactions.Actions
import com.kms.katalon.core.webui.common.WebUiCommonHelper
import com.kms.katalon.core.webui.driver.DriverFactory
Actions actions = new Actions(DriverFactory.getWebDriver());
actions.moveToElement(WebUiCommonHelper.findWebElement(findTestObject("path/to/object"), 30));
actions.click();
actions.sendKeys("Some Name");
actions.build().perform()
1 Like

In which format “Some Name” should be filled in?

e.g. like that? “C:\\Downloads\\test_data_1.xlsx”

for me it is clicking upload button, but then nothing uploading…

if you’re trying to upload a file, this might help;

thanks, but it did not help much

I can see upload window but nothing from file path is inserted…
I tried that code:

I think for some guys it can work and for some not, but it is not consistent solution for all…

did you try like this?

WebUI.uploadFile(findTestObject(‘Object Repository/Portal_Request_Page/upload_original_file_ button’), ‘C:\\Automation\\st12693.en07.doc’)

Does not work, getting error:

Test Cases/submit_request FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to upload file ‘C:\Automation\st12693.en07.doc’ to object (Root cause: java.lang.IllegalArgumentException: Object is null)
_ at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)_
_ at_

What does your test object look like? The more info you can give for your setup and what you’re trying to accomplish, the better.

well there is not much to catch locator by…hence it is not possible to use css or directly id…
Currently I’m capturing it by xpath: //*[@class=“mat-button-wrapper” and contains(text(), ‘Upload Original File’)]

in spy mode of katalon and browser elements I can find it easily with that xpath…but not with this uploadFile function

Using Inspect (right click on webpage) you can search for the Object in question by the xpath (//[@id=‘object’]). In my case I found that there were 2 versions of the object (1 of 2). By surrounding the xpath with parenthesis and indexing them ( **(//[@id=‘object’])[2]** ), I was able to see that the 1st one was ‘invisible’ and the 2nd one was displayed. So Katalon was finding the first and thus unable to interact with it. By setting my Test Object indexed at [2], my script worked.

Hope that was helpful?