Jump to content

Code for clicking a button by text not working in IE


Recommended Posts

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 :)

Link to comment
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 :)

Link to comment
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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
Share on other sites

  • Moderators
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"

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
Link to comment
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....

Link to comment
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=

Link to comment
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=

Link to comment
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
Link to comment
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

Link to comment
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=

Link to comment
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??

 

Link to comment
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
 Share

×
×
  • Create New...