Trying to execute onClick

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mnaeem
Junior Coder
Posts: 29
Joined: Wed Mar 10, 2021 5:05 pm

Trying to execute onClick

Post by mnaeem » Tue Mar 23, 2021 1:36 pm

Hello,

This is the html tag I want to press the onclick button but seems its not working. i am trying to avoid the OCR facility because image can change anytime.

Code: Select all

<input type="submit" onclick="2KKM25268FGTR0IDC6FIL04KV4_form_submit();" value="Continue" class="submit_input">
This is how I am approaching in my code. See the last 2 lines of code.

Code: Select all

//Let>CHROMEDRIVER_EXE=c:\chromedriver.exe
Let>CHROMEDRIVER_EXE=C:\ProgramData\chromedriver\chromedriver.exe
//start a chrome session
ChromeStart>session_id
//navigate to google.com
ChromeNavigate>session_id,url,https://www.abcdefg.com
//get some info 
ChromeGetInfo>session_id,url,theURL
ChromeGetInfo>session_id,title,theTitle
ChromeGetInfo>session_id,source,theSource
//find the input (name=userid)
ChromeFindElements>session_id,name,userid,elements
Wait> 1
//enter something into it
ChromeSetElementValue>session_id,elements_1,TomCruise
Wait> 1
//find the continue button and click it  -- NOT WORKING
ChromeFindElements>session_id,class,submit_input,elements
ChromeElementAction>session_id,elements_1,click
Regards

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Trying to execute onClick

Post by mightycpa » Tue Mar 23, 2021 4:16 pm

I don't know much about it, but what is the value of elements_1?

It seems to me that a class could represent many objects, whereas a name (like in the docs) will only represent one thing. Maybe you can't click an entire class, even if it is only used once.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mnaeem
Junior Coder
Posts: 29
Joined: Wed Mar 10, 2021 5:05 pm

Re: Trying to execute onClick

Post by mnaeem » Tue Mar 23, 2021 6:20 pm

Hello mightycpa,

Yes you are right, I am doing something wrong as elements_1 is not appearing in the Watch List while debugging.

This is the complete html for that button. I am trying to reach to that input element whose type is submit and execute the function mentioned in the onclick.

Code: Select all

<div class="button primary btnNext buttonMargin">
	<span class="buttonInner">
	          <input type="submit" onclick="2KKM25268FGTR0IDC6FIL04KV4_form_submit();" value="Continue" class="submit_input">
	        <span class="icon"></span>
	 </span>
</div>

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Trying to execute onClick

Post by mightycpa » Tue Mar 23, 2021 6:47 pm

The docs are a little vague, but they do say this:
Finds matching elements and returns an array of element IDs. Requires a session_id created by ChromeStart.

strategy can be one of:

id
name
class name
css selector
link text
partial link text
tag name
xpath

value takes the value of the item you are searching for.
Your code uses the strategy name, although I swear that I saw class in there earlier today. Either way, maybe it's that. Your button doesn't have a name, so that probably can't find it. The button only has a class. Try class name as your strategy.

Just a guess.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mnaeem
Junior Coder
Posts: 29
Joined: Wed Mar 10, 2021 5:05 pm

Re: Trying to execute onClick

Post by mnaeem » Tue Mar 23, 2021 6:58 pm

Following your suggestion, I tried these below 2 lines, but no luck page is not getting submitted.

Code: Select all

ChromeFindElements>session_id,class name,submit_input,elements
ChromeElementAction>session_id,elements_1,click
But this below code worked perfectly fine. Don't know why, I am still not convinced that the way I am submitting the page using this below line is the correct way to do things in MS.

Code: Select all

ChromeElementAction>session_id,elements_1,submit

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Trying to execute onClick

Post by Dorian (MJT support) » Wed Mar 24, 2021 11:54 am

I tend to rely quite heavily on XPath because it's so versatile.

Code: Select all

ChromeFindElements>session_id,xpath,//input[@type='submit'],el
ChromeElementAction>session_id,el_1,click
This will help understand a little more :
<input type="submit" onclick="2KKM25268FGTR0IDC6FIL04KV4_form_submit();" value="Continue" class="submit_input">

ChromeFindElements>session_id,xpath,//input[@type='submit'],el

Here are some snippets you can save. All you need to do is change "XX" accordingly, like I have above. This always follows exactly the same format.

Code: Select all

ChromeFindElements>session_id,xpath,//XX[@XX='XX'],el
//Get the element contents
ChromeGetElementData>session_id,el_1,text,increment_id

Code: Select all

ChromeFindElements>session_id,xpath,//XX[@XX='XX'],el
//Set the element to "Canada"
ChromeSetElementValue>session_id,el_1,Canada

Code: Select all

ChromeFindElements>session_id,xpath,//XX[@XX='XX'],el
//Perform an action
ChromeElementAction>session_id,el_1,click

Code: Select all

//A snippet containing all three.  Just use the lines you need.
ChromeFindElements>session_id,xpath,//XX[@XX='XX'],el
ChromeGetElementData>session_id,el_1,text,increment_id
ChromeSetElementValue>session_id,el_1,Canada
ChromeElementAction>session_id,el_1,click
Yes, we have a Custom Scripting Service. Message me or go here

mnaeem
Junior Coder
Posts: 29
Joined: Wed Mar 10, 2021 5:05 pm

Re: Trying to execute onClick

Post by mnaeem » Wed Mar 24, 2021 12:39 pm

Hi Dorian,

Thank you so much. You hit right. That is what I was looking for. I tried to go through docs but couldn't make my way out properly.

After using your suggested xpath approach I have realized that we can accurately reach to the desired element.

Appreciate your help.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Trying to execute onClick

Post by Dorian (MJT support) » Wed Mar 24, 2021 1:26 pm

Those colours and XXs will help you understand xpath, and once you understand that you'll be using it all the time. I suggest creating a snippet (in the snippets tab) so you have the 4 line sample easily at hand.
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts