Jump to content
MRAJ

Script not able to click on button type

Recommended Posts

MRAJ

My script not able to click on the Clear Numbers which is button type. Below is the script and HTML page of that.

<input onclick="clearSIFields(formx, this, 'fieldsinumber', 12)" type="button" value="Clear Numbers">

Local $oIE = _IECreate($URL,0,1)
Local $hWnd = WinWait("[CLASS:IEFrame]", "", 10)
 WinWaitActive($hWnd)
 Sleep(2000)
 ControlClick($hWnd, "Home - Internet Explorer", "[CLASS:IEFrame; INSTANCE:1]")
 Sleep(2000)

$oButtons = _IETagnameGetCollection($oIE, "input")

For $oButton in $oButtons
  
  If String($oButton.value) = "Clear Numbers" Then

        _IEAction($oButton, "click")

        ExitLoop
   EndIf
Next

let me know how to achieve this.

Share this post


Link to post
Share on other sites
Danp2

You haven't given us enough details. At a minimum, post the results shown in the Scite output panel when you run the script with F5.

You could also add some logging using ConsoleWrite() so that you can know things like how many elements were found, their values, etc. This will often allow you to see what is going wrong in your script and allow you to come up with a solution yourself.

Share this post


Link to post
Share on other sites
MRAJ

I am not seeing any errors in Output console. Let me know how i can use ConsoleWrite() to know how many elements were found? 

Share this post


Link to post
Share on other sites
Danp2

If you look at the help file for _IETagNameGetCollection, it states

Quote
Success: an object variable containing the specified Tag collection, @extended = specified Tag count.

So you could do something like this --

ConsoleWrite("*** " & @extended & " elements found! ***" & @crlf)

In addition, you could add a line to your loop to view details on each element, such as --

ConsoleWrite("Found - " & $oButton.value & @crlf)

The uses for ConsoleWrite are limitless! :lol:

Share this post


Link to post
Share on other sites
MRAJ

   Found the below output
*** 0 elements found! ***
"C:\Desktop\portal.au3" (35) : ==> Variable used without being declared.:
ConsoleWrite("Found - " & $oButton.value & @crlf)
ConsoleWrite("Found - " & ^ ERROR
>Exit code: 1    Time: 13.05
 

Share this post


Link to post
Share on other sites
Danp2

You need to figure out --

1) Why no elements were found with _IETagNameGetCollection

2) Why you received the variable not found error. On this one, I suspect that you put the ConsoleWrite outside of the For loop.

Share this post


Link to post
Share on other sites
MRAJ
$oButtons = _IETagnameGetCollection($oIE, "input")

For $oButton in $oButtons
  
   If StringInStr($oButton.value) = "Clear Numbers" Then

       _IEAction($oButton, "click")
ConsoleWrite("*** " & @extended & " elements found! ***" & @crlf)
Sleep(2000)
ConsoleWrite("Found - " & $oButton.value & @crlf)
       ExitLoop
   EndIf
Next

i tried like the above..is that correct?

Share this post


Link to post
Share on other sites
Danp2

No. The initial consolewrite would need to go directly after the call to _IETagNameGetCollection for the value of @extended to be correct. The other consolewrite should go directly after the For statement.

Share this post


Link to post
Share on other sites
MRAJ
$oButtons = _IETagnameGetCollection($oIE, "input")
ConsoleWrite("*** " & @extended & " elements found! ***" & @crlf)
For $oButton in $oButtons

   ConsoleWrite("Found - " & $oButton.value & @crlf)
 
   If StringInStr($oButton.value) = "Clear Numbers" Then

       _IEAction($oButton, "click")

Sleep(2000)

       ExitLoop
   EndIf
Next

i tried and output console gives below result:

*** 0 elements found! ***
>Exit code: 0    Time: 16.98

Share this post


Link to post
Share on other sites
MRAJ

No..the desired element i am not able to find.

Share this post


Link to post
Share on other sites
Danp2

That's an image. I was expecting you to save the web page's HTML to a file and post it here as an attachment.

P.S. What this bit about "5 frames found"? You have previously stated that there is only a single frame. :blink:

Share this post


Link to post
Share on other sites
MRAJ

<input onclick="clearSIFields(formx, this, 'fieldsinumber', 12)" type="button" value="Clear Numbers">

Please let me know the next step.Above is the HTML page for the particular Clear Numbers.

Share this post


Link to post
Share on other sites
Danp2

@MRAJ That's the same HTML you posted in your OP. This only shows us a single html element, which you are saying that you can't locate using the _IE functions. For further assistance, you will need to do as previously asked --

On 5/11/2018 at 8:41 AM, Danp2 said:

I was expecting you to save the web page's HTML to a file and post it here as an attachment.

Share this post


Link to post
Share on other sites
MRAJ

Attached is HTML page.

 

Edited by MRAJ

Share this post


Link to post
Share on other sites
Danp2

@MRAJ A quick review of this file shows that it doesn't contain the element you are attempting to click. It also reveals that there are 5 iframes involved.

You need to determine which iframe contains the desired elements before you can proceed any further.

Share this post


Link to post
Share on other sites
MRAJ

Could you help me the 5 frames which contains the desired elements and how to achiveve them..as i am not able to find any solution..i tired my best but not getting success.

Share this post


Link to post
Share on other sites
Danp2

Two options --

  • Use the browser's DOM Explorer to figure out which frame contains the desired elements.
  • Look at the help file example for _IEFrameGetCollection. Modify this to run against your webpage and see if you can determine which frame you need to access

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×