cancel
Showing results for 
Search instead for 
Did you mean: 

Use addEventListener for keyboard action

SOLVED
Highlighted
Frequent Contributor

Use addEventListener for keyboard action

Hi,

 

I've to input some textvalue in a textbox using the addEventListner because other options are not working out.

var txtbxq =  pgx.contentDocument.getElementById('cxqInput');

txtbxq.addEventListener("122-123-2212", otherparamsifrequired);

 

Can someone please let me know if that can be done using the event listener?  

 

Thanks in advance!!

-Al

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Frequent Contributor

Re: Use addEventListener for keyboard action

I got that working using the following. This is what I was looking for.

This was very easy, but the autocomplete feature never suggested any such property. 

var txtbxq =  pgx.contentDocument.getElementById('cxqInput');
txtbxq.value = ValForPhn;

 I'd still be curious to know what the addEventListener() could have done this such case. 

 

Thank you!

View solution in original post

8 REPLIES 8
Highlighted
Community Hero

Re: Use addEventListener for keyboard action

Not sure why you would do that but here's an older thread with a similar question

https://community.smartbear.com/t5/TestComplete-Functional-Web/addEventListener/td-p/191325

 

What else have you tried to use for entering text and what happened when you did?

Highlighted
Frequent Contributor

Re: Use addEventListener for keyboard action

 Hi @Marsha_R , 

 

I tried other functions such as Keys(), and SetText(). it doesn't support these functions. Probably because, I'm accessing the UI object using contentDocument. That's the reason I'm trying to explore other methods using which, I can set a text value in the textbox.

 

Also, I'm doing it in Javascript, so any example that you have other than keyword, please suggest. 

 

Thank you!

Highlighted
Community Hero

Re: Use addEventListener for keyboard action

Is there a particular reason you need to use contentDocument for this?  

Highlighted
Frequent Contributor

Re: Use addEventListener for keyboard action

I didn't want to create an Alias mapping of this object for so many reasons. One of the reasons is, it has so many layers, and TC  tries to map every single object in the path (I know this is how it works, but I'm avoiding that in some cases). Using contentDocument, I can directly access the object using getElementById. Regardless, I'm still hoping I can find a better way to instruct this for an action on this control since getElementById is a native DOM method.

 

Thank you!

Highlighted
Frequent Contributor

Re: Use addEventListener for keyboard action

I got that working using the following. This is what I was looking for.

This was very easy, but the autocomplete feature never suggested any such property. 

var txtbxq =  pgx.contentDocument.getElementById('cxqInput');
txtbxq.value = ValForPhn;

 I'd still be curious to know what the addEventListener() could have done this such case. 

 

Thank you!

View solution in original post

Highlighted
Community Hero

Re: Use addEventListener for keyboard action

Hi,

 

Unless you are talking about something else than https://www.w3schools.com/jsref/met_element_addeventlistener.asp, I am doubting that this method can be of any help with text input into control.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Frequent Contributor

Re: Use addEventListener for keyboard action

@AlexKaras  I was trying to find out if the eventListener would be helpful in simulating Keyboard action  to help me input values in a textbox. What I posted in solution does the work, but I was trying to find out way to Key values into a textbox <input type="text" id="ccPxk_01"> one by one.

 

If I use Alias Mapping for a textbox, it's fairly easy to do it by using Keys() method, but in this case where I'm using contentDocument object,  the method Keys() is not supported. 

 

Thank you!

Highlighted
Community Hero

Re: Use addEventListener for keyboard action

Hi,

 

 in this case where I'm using contentDocument object,  the method Keys() is not supported.

This is correct and expected behavior. .Keys() is a method that is added by TestComplete to any method found via the means provided by TestComplete. .contentDocument property provides a reference to native DOM and then you are using native DOM methods as well, thus TestComplete has no idea about what objects your test code accesses and operates with.

So, either you are working on TestComplete's level and has access to all methods and properties added by TestComplete (in addition to those provided by DOM) or you are working on the DOM level and use only methods and properties provided by DOM.

 

P.S. The situation is like the one that exists in .Net, for example. Your code may work within .Net framework bounds and use the functionality like metadata, type control, etc. Or the code may get a reference to native OS level and operate via native Win32/Win64 functions. But at the cost of metadata, type control and so on.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors