Jump to content
Hanukka

Code for clicking a button by text not working in IE

Recommended Posts

@Hanukka first and foremost, why are you asking a jquery question on an AutoIt forum? :huh2:

Secondly, if you are trying to accomplish this in AutoIt, how about posting what you have tried on your own up to this point? This forum is for assisting people with their own scripts; it is not a place where you put in an order and someone barfs up code for you. 

Share this post


Link to post
Share on other sites

And BTW:
Please give meaningful titles to your threads. The better you describe your problem in the title the more help you will get. Everyone is looking for a solution on this forum - that's what it is made for ;)
 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Could somebody tell me what is wrong in the code to click the button "run code snippet" in the link mentioned in the code below:-

#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery')
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
MouseClick("primary", 1358, 697, 15, Default) ;;; Just to reaach to the run code snippet menu
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.value) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
Next
Sleep(5000)
_IEQuit($oIE) 

for more convinience the link is:- 'https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery'

It gives no output..BTW i am guessing button.value is wrong,  but then how to choose the button by the text  'Run code snippet' ?

Any help would be appreciated :)

Share this post


Link to post
Share on other sites

Could somebody tell me what is wrong in the code to click the button "run code snippet" in the link mentioned in the code below:-

#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery')
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
MouseClick("primary", 1358, 697, 15, Default) ;;; Just to reaach to the run code snippet menu
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.value) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
Next
Sleep(5000)
_IEQuit($oIE) 

for more convinience the link is:- 'https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery'

It gives no output..BTW i am guessing button.value is wrong,  but then how to choose the button by the text  'Run code snippet' ?

Any help would be appreciated :)

Share this post


Link to post
Share on other sites

@JLogan3o13..chill bruh. I didnot post my code cuz i couldnt do shit in it..btw here it is:

#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery')
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
$frame = _IEFrameGetObjByName($oIE, 'a3370ed0-a917-e85c-938a-c1d8c4aa8673');;;;Can't even get this frame :s
Sleep(5000)
_IEQuit($oIE)

The output is shown as ' --> IE.au3 T3.0-2 Warning from function _IEFrameGetObjByName, $_IESTATUS_NoMatch (No frames matching name) '

I guess i havent yet understood the right way of accessing frames..can somebody pls help

Also i guess this is very much an autoit question..I dont know if there is a method to solve this using jquery.

@water..sure man...could you please help me out with this?

I guess the frame name gets dynamically created...If so, how to make it work with that??

Edited by Hanukka

Share this post


Link to post
Share on other sites

I won't be of much help as I do not work with the IE UDF :(


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery', 1)
_IELoadWait($oIE)
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.innertext) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
Next

 

Share this post


Link to post
Share on other sites

@Subzero....so it was 'inner text'...Thanks a lot bruh!!

On 6/6/2017 at 7:11 PM, Hanukka said:

want to check the checkbox in the frame which pops up after choosing "run code snippet" option. ( Internet Explorer one would be prefered )

Can somebody also help me with this??.....The frame the checkbox is in gets dynamically created, so i dont know how to access the frame itself.

And @JLogan3o13..dude pls help me out with my doubts rather than ordering them and all.

Share this post


Link to post
Share on other sites
7 hours ago, Hanukka said:

And @JLogan3o13..dude pls help me out with my doubts rather than ordering them and all.

You are getting help, but you also need to follow the rules of the forum. Posting your question multiple times makes it more difficult for people trying to help you..."bruh"

Share this post


Link to post
Share on other sites

@Danp2..Alright mate..i've tried this..pls have a look:-

#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery', 1)
_IELoadWait($oIE)
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
$oIE.document.parentwindow.scroll(0, $oIE.document.body.scrollHeight/(10)) ;;;get to the button area
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.innertext) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
Next
$oFrame = _IEFrameGetCollection($oIE, 0) ;;It is the first frame itself
$input = _IEGetObjById($oFrame, 'isAgeSelected')  ;; The id of the input check box in it
;_IEAction($input, 'click') ;;;gives an error in the previous statement only!!!!!

The error it throws is:

 ==> The requested action with this object has failed.:

If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject^ ERROR

* Also those stack overflow ppl haven't provided <form> tags...which makes me really confused

pls help @water, @Subz..o:)

And @JLogan3o13...cool bruh.. ill follow them rulzz

Edited by Hanukka

Share this post


Link to post
Share on other sites
1 hour ago, Hanukka said:

@Danp2..Alright mate..i've tried this..pls have a look:-

#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery', 1)
_IELoadWait($oIE)
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
$oIE.document.parentwindow.scroll(0, $oIE.document.body.scrollHeight/(10)) ;;;get to the button area
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.innertext) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
Next
$oFrame = _IEFrameGetCollection($oIE, 0) ;;It is the first frame itself
$input = _IEGetObjById($oFrame, 'isAgeSelected')  ;; The id of the input check box in it
;_IEAction($input, 'click') ;;;gives an error in the previous statement only!!!!!

The error it throws is:

 ==> The requested action with this object has failed.:

If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject^ ERROR

* Also thosestack overflow ppl haven't provided <form> tags...which makes me really confused

pls help @water, @Subz..o:)

And @JLogan3o13...cool bruh.. ill follow themrulzz

1 hour ago, Hanukka said:

@Danp2..Alright mate..i've tried this..pls have a look:-

#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery', 1)
_IELoadWait($oIE)
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
$oIE.document.parentwindow.scroll(0, $oIE.document.body.scrollHeight/(10)) ;;;get to the button area
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.innertext) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
Next
$oFrame = _IEFrameGetCollection($oIE, 0) ;;It is the first frame itself
$input = _IEGetObjById($oFrame, 'isAgeSelected')  ;; The id of the input check box in it
;_IEAction($input, 'click') ;;;gives an error in the previous statement only!!!!!

The error it throws is:

 ==> The requested action with this object has failed.:

If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject^ ERROR

* Also thosestack overflow ppl haven't provided <form> tags...which makes me really confused

pls help @water, @Subz..o:)

And @JLogan3o13...cool bruh.. ill follow themrulzz

Hm.  This may be a bit more difficult than initially thought.  Here is the info for the button you want to click:

vwHBTrm.png

No name or ID property.  You may have to reference it by index....

Share this post


Link to post
Share on other sites

Alright, I've worked out that this is an issue with the iFrames on stackoverflow. You will get an Access Denied error like so:

err.number is:      0x80020009
    err.windescription: Exception occurred.

    err.description is:     Access is denied.

    err.source is:      
    err.helpfile is:    C:\Windows\System32\mshtml.hlp
    err.helpcontext is:     0
    err.lastdllerror is:    0
    err.scriptline is:  1899
    err.retcode is:     0x80070005

if you try to access the elements in the iframe. Apparently this is due to an XSS restriction, the iframe might be hosted on another url, but I can't find the link anywhere.

Here's my code in case someone else wants to give it a shot:

#AutoIt3Wrapper_UseX64=Y
#include <IE.au3>

_IEErrorHandlerRegister(_User_ErrFunc)

$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery', 0)
_IELoadWait($oIE)
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
$oIE.document.parentwindow.scroll(0, $oIE.document.body.scrollHeight/(10)) ;;;get to the button area
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.innertext) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
Next

Sleep(2000)
$oIE = _IEAttach("Stack Overflow")
$oFrames = _IEFrameGetCollection($oIE) ;It is the first frame itself
$iLength = $oFrames.length
;MsgBox(64, "Test", ".length = " & $iLength)

Local $checkBox
Local $oFrame

For $i=0 To $iLength-1
    $oFrame = _IEFrameGetCollection($oIE, $i)
    If @error Then
        MsgBox(0, "d", @error)
    EndIf
    If(IsObj($oFrame)) Then
        If (_IEGetObjById($oFrame, "isAgeSelected")) Then
            If Not $checkBox.checked Then
                $checkBox.checked = True
            EndIf
            ExitLoop
        EndIf
    EndIf
Next

;_IEAction($input, "click") ;;;gives an error in the previous statement only!!!!!

; User's COM error function.
; After SetUp with ObjEvent("AutoIt.Error", ....) will be called if COM error occurs
Func _User_ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_User_ErrFunc

It fails on the line "If (_IEGetObjById($oFrame, "isAgeSelected")) Then"


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

Thanks for helping out guys...although the solution couldnt be reached..I don't have enough knowledge about this to work on it, but is it possible to get this under the spotlight?..Like to the folks who have contributed to the IE UDFs??

But I still wonder that why would a site like stack overflow, itself using https protocol, have a XSS restriction? :blink:

 ✌️

^ Also the code fails on both IE8 and IE11

Edited by Hanukka

Share this post


Link to post
Share on other sites
16 hours ago, MattHiggs said:

Hm.  This may be a bit more difficult than initially thought.  Here is the info for the button you want to click:

vwHBTrm.png

No name or ID property.  You may have to reference it by index....

Bro...the button worked fine, the problem was that the next frame which pops up after clicking it, which has the checkbox, that I am unable to access...the button can be clicked by index and also by innerText as mentioned by @Subz

Share this post


Link to post
Share on other sites
On 6/9/2017 at 1:13 AM, Hanukka said:

Thanks for helping out guys...although the solution couldnt be reached..I don't have enough knowledge about this to work on it, but is it possible to get this under the spotlight?..Like to the folks who have contributed to the IE UDFs??

But I still wonder that why would a site like stack overflow, itself using https protocol, have a XSS restriction? :blink:

 ✌️

^ Also the code fails on both IE8 and IE11

This isn't a limitation of the UDF or the website, it's a limitation of all browsers in general. They purposely deny XSS for security reasons.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

Guys, I gave it a bit of sleep time, since some frames get dynamically created n i thought that the script ran before the frame was created. The frame creation gave no error but I am still not able to access the inner check box. Pls have a look at the code:-

#include <IE.au3>
$oIE = _IECreate('https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery', 1)
_IELoadWait($oIE)
WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
$oIE.document.parentwindow.scroll(0, $oIE.document.body.scrollHeight/(10))
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.innertext) = " Run code snippet" Then
       _IEAction($oButton, "click")
    EndIf
 Next
 Sleep(5000)
$oframe = _IEFrameGetCollection($oIE, 0) ;The first frame
;MsgBox(0, "", @error) ; error flag is 0
Sleep(2000)
$tag = _IETagNameGetCollection($oframe, 'input', 0) ; The first checkbox input tag
;_IEAction($tag, 'click') ; checks the checkbox

 

It gave a new error this time, which again is mandarin to me :(

 ==> The requested action with this object has failed.:

Return SetError($_IESTATUS_Success, 0, $oObject.document)
Return SetError($_IESTATUS_Success, 0, $oObject^ ERROR

@anthonyjr2...still the same XSS problem leading to this, mate??

 

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

  • Similar Content

    • By TrashBoat
      Im trying to iterate through a 2d array created by 
      ProcessList() function that returns a 2d array containing names and pid's, i wanted to filter through the names and delete entries that have "svchost.exe" and this is how i did it
      Func _Sanitize($array) For $x = 1 To UBound($array) - 1 ConsoleWrite($array[$x][0] & @CRLF) If $array[$x][0] == "svchost.exe" Then _ArrayDelete($array, $x) EndIf Next EndFunc ;==>_Sanitize And i get this error message
      What is wrong?
    • By gahhon
      Global Const $DIR_WA_FOLDER = @MyDocumentsDir & '\Whatsapp Extension' Global Const $DIR_SHORTCUT = @DesktopDir & '\WhatsappWeb.exe' Func _Create_Shortcut() Local $sMessage = "Creating shortcut " _Metro_SplashTextScreen(1, "", $sMessage) AdlibRegister("_Metro_LoopInProgress") If FileExists($DIR_WA_FOLDER) Then $iDelete = FileDelete($DIR_SHORTCUT) If $iDelete Then _FileWriteLog($LOG_INSTALLATION, "Debug: Desktop's shortcut is deleted.") Else _FileWriteLog($LOG_INSTALLATION, "Debug: Desktop's shortcut is not found. But, desktop's shortcut is still created.") EndIf If FileExists($DIR_WA_FOLDER & '\WhatsappWeb.exe') Then $iCreate = FileCreateShortcut($DIR_WA_FOLDER & '\WhatsappWeb.exe', $DIR_SHORTCUT) If $iCreate Then _Metro_MsgBox(0, "", "Desktop shortcut is now created!") _FileWriteLog($LOG_INSTALLATION, "Debug: Desktop's shortcut is created.") Else _Metro_MsgBox(0, "", "Desktop shortcut is failed to created!") _FileWriteLog($LOG_INSTALLATION, "Error: Fail to create shortcut.") EndIf Else _Metro_MsgBox(0, "", "Source not found!") _FileWriteLog($LOG_INSTALLATION, "Error: WhatsappWeb.exe is not found.") EndIf Else _Metro_MsgBox(0, "", "Source not found!") _FileWriteLog($LOG_INSTALLATION, "Error: Whatsapp Extension folder is not found.") EndIf AdlibUnRegister("_Metro_LoopInProgress") _Metro_SplashTextScreen(0) EndFunc So I do have a button to trigger this create shortcut to desktop.
      But after it created shortcut at desktop, I cannot execute the shortcut as it has no any response.
      Then I go try trigger the file at the source path @MyDocumentDir & '\Whatsapp Extension\WhatsappWeb.exe' and it work as expected.
      Then I go to check my log, and it shows:- (P/S: I already did trigger the function twice)
      2019-02-28 23:27:32 : Debug: Desktop's shortcut is not found. But, desktop's shortcut is still created. 2019-02-28 23:27:33 : Debug: Desktop's shortcut is created. 2019-02-28 23:28:40 : Debug: Desktop's shortcut is not found. But, desktop's shortcut is still created. 2019-02-28 23:28:41 : Debug: Desktop's shortcut is created. So based on my log shows, it failed to locate the shortcut, but it did exists there.
       
      P/S: This project is done developed weeks ago, every testing is passed. Is just somehow the executable cannot be execute.
       
       
      Any advise?
    • By chrweav86
      Here is an existing AS400 PCOM script that I have: 
      #include-once
      #cs ----------------------------------------------------------------------------
       UDF Header Title: _PCOMM
       UDF Header Version: 0.1.0
       AutoIt Version: 3.3.8.1
       Author:         Jason S. - Jewelry Supply, Inc.
       Script Function: PCOMM UDF Header
                          For use with IBM AS/400 - IBM OS/400 - IBM System i - IBM i application system.
                          This PCOMM UDF Header targets ASW - an ERP application suite written in IBM's RPG language (yuck!),
                          although it will work for any AS/400 system and is not ASW specific.
                          PCOMM allows injection of keystrokes into the datastream of
                          a running terminal/console application ("Green Screen" Console Emulator).
                              - Assumes Session 'A' but can be overriden using the aswConnect() function.
                          PCOMM allows observing of characters in the datastream of a running
                          terminal/console application ("Green Screen" Console Emulator).
                              - Assumes Session 'A' but can be overriden using the aswConnect() function.
      #ce ----------------------------------------------------------------------------
      Global $Session = "A"
      Global $Ps
      Global $Oia
      ; Specify session to connect to
      Func aswSetSession($nSession)
          $Session = $nSession
      EndFunc
      ; Connect to ASW
      ; @param $nSession - Specify session to connect to. Ex: "A"
      Func aswConnect($nSession = $Session)
          $Obj_ConnMgr = ObjCreate("PCOMM.autECLConnMgr")
          $OBJ_EmulSession = ObjCreate("PCOMM.autECLSession")
          $OBJ_EmulSession.SetConnectionByName($nSession)
          $Ps = $OBJ_EmulSession.autECLPS
          $Oia = $OBJ_EmulSession.autECLOIA
      EndFunc
      ; Send Data to ASW
      ; if $rownum and $colnum are not specified, defaults to the cmd line
      Func aswSend($keys, $rownum = 20, $colnum = 7, $inhibit = 1)
          $Ps.SendKeys($keys, $rownum, $colnum)
          if $inhibit = 1 Then
              While $Oia.InputInhibited <> 0
              WEnd
          EndIf
          $Oia.WaitForInputReady()
      EndFunc
      ; Get Data from ASW
      Func aswGet($row, $col, $length)
          $info = $Ps.GetText($row,$col,$length)
          return $info
      Endfunc
      ; Check which page we are on
      ; @param $page - Page to see if we are on. Ex: "DMR30101" == Sales Order Maintenance page
      Func checkScreen($page, $rownum = 1, $colnum = 72, $length = 8)
          If StringInStr(aswGet($rownum, $colnum, $length), $page) Then
              Return 1
          Else
              Return 0
          EndIf
      EndFunc
      I would like to use it launch a connection to the AS400. I have an executable that I run with an hod file. Do I just need to run the exe and hod file then run the session connect function and send keys function to pass credentials?
       
    • By FordsFinest
      Have come across an issue where I use the below code to select and then click an item. It works great on every computer but one, which happens to be my bosses computer (of course right lol).  So SelectItem works fine, but for some reason, the ClickItem command keeps clicking the item below the correct item (but only on this computer. I changed the command to controlsend instead, but i'd rather use the click option.. any ideas here?
       
      _GUICtrlTreeView_SelectItem($hWnd, $Array2[1]) _GUICtrlTreeView_ClickItem($hWnd, $Array2[1], "right")  
    • By gahhon
      So I had compiled my AutoIT script into executable file, I think like few weeks ago.
      But once after I compiled the script to executable file, I tested it and it work as expected.
      Somehow, I just now wanna try to execute it but failed

      Any idea what's is going on? Do I need to recompile the script again? @@
×
×
  • Create New...