Sign in to follow this  
Followers 0
aha

Getting form elements in Maxthon

4 posts in this topic

Hi,

I am trying to code an autoit script to login into a webpage in Maxthon. Now I am stucked because I couldn't identify the form elements using the functions in IE.au3. Could anyone take a look at my code and any advices are very much appreciated.

I also attached an error msg I received.

aha

Here is my code:

-------------------------------------------

#include <IE.au3>

Local $IEhandle

; Run Mathxon

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

If Not WinExists("- Maxthon Browser") Then

Run("Maxthon.exe")

Do

Sleep(10)

Until WinExists("- Maxthon Browser")

Else

WinActivate("- Maxthon Browser","")

EndIf

WinWaitActive("- Maxthon Browser","",15)

$IEhandle=WinGetHandle("- Maxthon Browser")

Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

; Open an blank page in Maxthon

ControlClick($IEhandle, "", "[Class:ToolbarWindow32; Instance:5; ClassnameNN:ToolbarWindow325]", "left", 1, 18, 18)

Sleep(500)

;input the website url

ControlSend($IEhandle,"", "[Class:Edit; Instance:2; ClassnameNN:Edit2]","www.gmail.com{ENTER}")

$obj_Maxthon=_IEAttach($IEhandle, "embedded")

_IELoadWait($obj_Maxthon)

;Sleep(5000)

;MsgBox(64,"ObjName", ObjName($obj_Maxthon))

; get pointers to the login form and username and password fields

$o_form = _IEFormGetObjByName($obj_Maxthon, "loginform")

;MsgBox(64,"@Error", @Error)

$o_login = _IEFormElementGetObjByName($o_form, "username")

$o_password = _IEFormElementGetObjByName($o_form, "password")

; Set field values and submit the form

_IEFormElementSetValue($o_login, "your username here")

_IEFormElementSetValue($o_password, "your password here")

Sleep(2000)

_IEFormSubmit($o_form)

Exit

Share this post


Link to post
Share on other sites



Hi,

I am trying to code an autoit script to login into a webpage in Maxthon. Now I am stucked because I couldn't identify the form elements using the functions in IE.au3. Could anyone take a look at my code and any advices are very much appreciated.

I also attached an error msg I received.

aha

Here is my code:

#include <IE.au3>

Local $IEhandle

; Run Mathxon
Opt("WinTitleMatchMode", 2)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
If Not WinExists("- Maxthon Browser") Then
    Run("Maxthon.exe")
    Do
        Sleep(10)
    Until WinExists("- Maxthon Browser")
Else
    WinActivate("- Maxthon Browser","")
EndIf

WinWaitActive("- Maxthon Browser","",15)
$IEhandle=WinGetHandle("- Maxthon Browser")

Opt("WinTitleMatchMode", 1)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

; Open an blank page in Maxthon
ControlClick($IEhandle, "", "[Class:ToolbarWindow32; Instance:5; ClassnameNN:ToolbarWindow325]", "left", 1, 18, 18)
Sleep(500)

;input the website url
ControlSend($IEhandle,"", "[Class:Edit; Instance:2; ClassnameNN:Edit2]","www.gmail.com{ENTER}")

$obj_Maxthon=_IEAttach($IEhandle, "embedded")
_IELoadWait($obj_Maxthon)
;Sleep(5000)

;MsgBox(64,"ObjName", ObjName($obj_Maxthon))

; get pointers to the login form and username and password fields
$o_form = _IEFormGetObjByName($obj_Maxthon, "loginform")
;MsgBox(64,"@Error", @Error)
$o_login = _IEFormElementGetObjByName($o_form, "username")
$o_password = _IEFormElementGetObjByName($o_form, "password")

; Set field values and submit the form
_IEFormElementSetValue($o_login, "your username here")
_IEFormElementSetValue($o_password, "your password here")
Sleep(2000)
_IEFormSubmit($o_form)

Exit
well i have no idea what maxthon is but the submit might not work because some pages have costom java script

[center]JSON Encoding UDF[/center]

Share this post


Link to post
Share on other sites

You're making debugging much harder for yourself than necessary. Please install SciTe for AutoIt and run your script from there (Tools -> Go) because IE.au3 outputs many helpful diagnostics to the SciTe console. Also, place the following line at the top of your script to see the progress of your script:

#AutoIt3Wrapper_run_debug_mode=Y

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thank you, Dale. I don't know SciTe can do that.

Here are the messages posted in SciTe. Is it because the form name I supplied to the _IEFormGetObjByName function wasn't correct? If so, where can I find the right form name to supply here?

Thanks again for your help.

aha

[debug msg from SciTe]

0044: 0-0: _IELoadWait($obj_Maxthon)

--> IE.au3 Warning from function _IELoadWait, $_IEStatus_AccessIsDenied (Cannot verify readyState. Likely casue: cross-site scripting security restriction.)

0045: 8-0: Sleep(5000)

0050: 0-0: $o_form = _IEFormGetObjByName($obj_Maxthon, "f1")

C:\Program Files\AutoIt3\Include\IE.au3 (1135) : ==> The requested action with this object has failed.:

$o_col = $o_object.document.forms.item ($s_Name)

$o_col = $o_object.document^ ERROR

->14:35:09 AutoIT3.exe ended.rc:1

+>14:35:10 AutoIt3Wrapper Finished

>Exit code: 1 Time: 8.855

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
Sign in to follow this  
Followers 0