Hanukka

Code for clicking a button by text not working in IE

20 posts in this topic




#2 ·  Posted

@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

#3 ·  Posted

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

#4 ·  Posted

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

#5 ·  Posted

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

#7 ·  Posted

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

#8 ·  Posted

#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

#9 ·  Posted

@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

#10 ·  Posted

@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

#11 ·  Posted

Have you tried using _IEFrameGetCollection?

1 person likes this

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

#14 ·  Posted

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

#15 ·  Posted

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

#16 ·  Posted

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

#18 ·  Posted

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

#19 ·  Posted

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

#20 ·  Posted

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

    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • Viki
      By Viki
      This is my first time here so please dont bombard me that what a silly question I am asking!!
      I have 500 rows (A1:A500) in a spreadsheet and I just want to copy one by one row and then paste into another application and then press enter, loop should repeat this until finishes all 500 rows.
      I have looked at clipget(), clip(put() but dont know how to select next row in next turn. I also looked at Array to store but again no luck. Can some guide me please..
    • DineshPawar
      By DineshPawar
      0down votefavorite   In my current project, Excel macro open AutoIt script using a function Call Shell("location of autoit script").
      For proper functioning of AutoIt script it's need to be close parent Excel workbook, so this closing Excel action is written in AutoIt script itself.
      But as soon as AutoIt script close parent Excel workbook then script get pause and it do nothing.
      How open the AutoIt script from Excel workbook and after that parent Workbook get close?