Hanukka

Code for clicking a button by text not working in IE

20 posts in this topic




@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. 


√-1 2^3 ∑ π, and it was delicious!

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

#6 ·  Posted (edited)

@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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

 

1 person likes this

Share this post


Link to post
Share on other sites

@Hanukka stick to one topic from now on, please. Threads merged.


√-1 2^3 ∑ π, and it was delicious!

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

Have you tried using _IEFrameGetCollection?

1 person likes this

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"

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

@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....

1 person likes this

Share this post


Link to post
Share on other sites

The problem seems to be that the checkbox is inside an iframe, and for some reason I can't seem to get it to recognize the frame as an object. I can't call _IEGetObjByID on the frame. I'm not sure if it's a problem with newer versions of IE or the UDF...


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

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"

1 person likes this

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

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.

1 person likes this

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

    • JSmith312
      By JSmith312
      Hello Everyone! 
      I'm attempting to create a checklist app that performs other functions. For performance, I would like to check the box, then have the button to the right enabled. After that button is pressed, the second checkbox is enabled, and ready to be checked, allowing the second button to be pressed. After the second button is pressed, the completion/exit button is enabled/shown. I have my code that currently creates the GUI, creates the checkbox, but when you check it it enables the button and the next checkbox. Can't seem to figure out a Case for GUISetOnEvent. Any assistance would be appreciated!
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <MsgBoxConstants.au3> ; Below is the GUI interface _DeploymentProcess() Func _DeploymentProcess() $aStep1 = GUICreate("Deployment Process", 475, 345, 500, 175) $CBcStep1 = GUICtrlCreateCheckbox("1. Step 01.", 15, 25, 300, 25) $BTNS1 = GUICtrlCreateButton("Email 01", 365, 25, 90, 20) $CBcStep2 = GUICtrlCreateCheckbox("2. Step 02.", 15, 50, 300, 25) $BTNS2 = GUICtrlCreateButton("Email 02", 365, 50, 90, 20) GUICtrlSetState($CBcStep2, $GUI_DISABLE) GUICtrlSetState($BTNS1, $GUI_DISABLE) $CBcStep3 = GUICtrlCreateButton("Hurray! You're Complete!", 85, 276, 300, 60) GUICtrlSetState($CBcStep3, $GUI_SHOW) ; Below are the button and checkbox enables/disables. GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($aStep1) Return ; Step 1 Case $CBcStep1 If GUICtrlRead($CBcStep1) = $GUI_CHECKED Then GUICtrlSetState($BTNS1, $GUI_ENABLE) GUICtrlSetState($CBcStep2, $GUI_ENABLE) Else GUICtrlSetState($BTNS1, $GUI_DISABLE) GUICtrlSetState($CBcStep2, $GUI_DISABLE) EndIf ; Step 2 Case $CBcStep2 If GUICtrlRead($CBcStep2) = $GUI_CHECKED Then GUICtrlSetState($BTNS2, $GUI_ENABLE) GUICtrlSetState($CBcStep3, $GUI_ENABLE) Else GUICtrlSetState($BTNS2, $GUI_DISABLE) GUICtrlSetState($CBcStep3, $GUI_DISABLE) EndIf Case $CBcStep3 If GUICtrlRead($CBcStep2) = $GUI_CHECKED Then GUICtrlSetState($BTNS10, $GUI_ENABLE) GUICtrlSetState($CBcStep3, $GUI_SHOW) Else GUICtrlSetState($CBcStep3, $GUI_EVENT_CLOSE) EndIf Case $GUI_EVENT_CLOSE, $CBcStep3 #comments-end Exit EndSwitch WEnd EndFunc  
    • Pere
      By Pere
      Hi all,
      I've written the script below to automatically login to a website, in this case infusionsoft.com
      The auto login works fine. Is there a way for me to get errors from Internet explorer, if the login fails because of wrong login credentials. I have searched around, but cannot make sense of this.
      Please forgive me if I have overlooked something simple. I am new to autoit. Please see my script below.
      #include <IE.au3>
      #include <MsgBoxConstants.au3>

      Func AccountAutoLogin()
         ;This line sets the website page to open and inject information
         Global $oIE = _IECreate("https://signin.infusionsoft.com/login")
         ;set the variables to pull the username and password object names
         Local $username = _IEGetObjByName ($oIE, "username")
         Local $password = _IEGetObjByName ($oIE, "password")
         ;set the $oButtons variable to pull all the values of the button class
         Local $oButtons = _IETagnameGetCollection($oIE, "button")
         ;set the username and password values on the login form
         _IEFormElementSetValue ($username, "")
         _IEFormElementSetValue ($password, "")
         ; loop through the button class until we find the text on the login button, then click the button
         For $oButton in $oButtons
            If String($oButton.value) = " Log In " Then $test = $oButtons
               _IEAction($oButton, "click")
               _IELoadWait($oIE)
               if (@error) then MsgBox (0, "Error", @error)
            ExitLoop
         Next
      EndFunc
    • AnonymousX
      By AnonymousX
      Hello, 
      I'm trying to write a script that can go to a specific work related webpage, then grab the html text out of a known recorded comment field. I have a basic understanding of HTML, but I'm confused by the website as when I open up source code I get something called frames/iframes. Not sure what that really is.... 
      Anyways using chrome and opening up source code it made a little more sense, and could trace all content I want falls within what I see as "top/mainFrame (retrieve.do)/notesActionHistoryHistory (iframeComments.jsp)/bcwebapp:8500/oinc"
       
      Is there an easy way to make a variable contain all the html text within this frame?
       
       
      Background:
      Website is on companies intranet, and each project has it's own page. I need a way to go through an excel list of projects, open up the webpage to the respective projects, then grab all the comments for those projects, then paste everything into 1 text file. My idea is to copy the excel list into an array, then use it to go one by one to the different webpages and copy the comments into an array, then paste it all into a text file. I've pretty much got all the pieces figured out, except how to grab the actual html comment data. I can do it manually but who wants to do that...
       
      Thanks for any help in advance
    • RoundChecker
      By RoundChecker
      Hi everyone,

      Is there a way to determine whether the script that is running, is already running, without using;
       
      If WinExists ?

      Or is there a way to use "If WinExists" to determine the script itself?

      The reason I am asking this is because if I want someone to run the .Exe I have and they rename it to whatever they want, how could I then determine in the script to check if there's already an .Exe open, or the script itself is already open?

      Should I use Class, or how do I achieve this?

      Thanks in advance.
    • svenjatzu
      By svenjatzu
      Id like to build a little helpertool for my boss in office but i dont know how to sart it.
      thats no complicated task. im working for an insurancecenter and have to search the customers in different orders and different tags.
      due to my boss is old and not really commen with pc he saves the customers without system.
      eg, customer andreas statham got an insurenca for his car then i got to search for
      andreas statham car, andreas car statham, car andreas statham, statham andreas car, statham car andreas, car statham andreass etc to find all the files from this customer in the harddrive.
      some customers also are fmiliarnamed in one file like andreas statam and monika rog are married an both got a carinsurance then i got to earch for
      andreas statham monika rog car, andreas statham monika car rog,.... this can take real long to find the right customer if i do it from hand.
      how can i realise this someone in here got an excamlple script or has any sugestion?