Jump to content

Getting an object without ID or Name - (Moved)


Recommended Posts

Hello all,

 

Im currently trying to write a script able to click on a button/image, but this one isn't having any link/name/id linked to. The only thing it has is a class name (which seems variable) and a data-num.

Operations wanted would be like : 

-Open IE with specific URL

-Get Source

-Search the string of the image (which is :  " data-num="30">30</div> " )

-And finally click on the image corresponding to this string

 

Hope some of you will understand my request and know how i can write my script , I'm also able to provide more informations/pictures if needed !

thx

Link to post
Share on other sites
  • Developers

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

@HugoNatalis Look at the _IEImgGetCollection and the example that comes with it.  If you still need help post your code here along with the DOM of the associated image you want to get at.

Link to post
Share on other sites

@HugoNatalis

It's not that hard as it seems :)

If you "split" the work (as you already did), you can see that you can use:

  • _IECreate() to open IE with the URL you want;
  • _IEDocReadHTML() to get the source of the document;
  • Loop through the return value of the above function to get what you are looking for;
  • Once you get it, use _IEAction() or any _IE* function to click the item you were looking for.

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites
32 minutes ago, HugoNatalis said:

Seems very hard to do

Open Example 2 of _IEImgGetCollection, change the url to yours. Save as the script in your personal folder.  Press F5. Printscreen the result, paste (Ctrl-V) here. Voilà !

Link to post
Share on other sites

So, after a few talks with @Nine (which i thank btw), my code to catch and click the objet I want is not working.

 

Here is my code,

The website to access is private, if some of you feel able to help me to code this i will give you the access to the website.

#include <IE.au3>

HotKeySet("{esc}", "_Exit")
func _Exit()
    Exit
EndFunc


Global $oIE = _IECreate("http://www.lycee-champblanc.net/resa.php")
WinSetState(_IEPropertyGet($oIE,"hwnd"),"",@SW_MAXIMIZE)
_IELoadWait($oIE)
Sleep(2500)

SignIn()

Func SignIn()

Do
    Local $user = _IEGetObjByName($oIE,"username")
    Local $pwd = _IEGetObjByName($oIE,"password")
    Local $button = _IEGetObjById($oIE,"but_login")

    _IEFormElementSetValue($user,"My-Username")
    _IEFormElementSetValue($pwd,"My-Password")
    _IEAction($button,"click")
    _IELoadWait($oIE)

    _IELoadWait($oIE)
    Sleep(2500)

    $sujet1 = _IEDocReadHTML ($oIE)
    $refreshornot = "L'identifiant ou le mot de passe saisi est incorrect"

    $resultat1 = StringRegExp($sujet1, $refreshornot, $STR_REGEXPMATCH)

Until $resultat1 = 0

    _IELoadWait($oIE)
    Sleep(2500)

Local $oInputs = _IETagNameGetCollection($oIE, "div")
Local $sTxt = ""
For $oInput In $oInputs
    $sTxt &= $oInput.className & @CRLF
Next
MsgBox($MB_SYSTEMMODAL, "Form DIV Type", "Form: " & $oInput.form.name & @CRLF & @CRLF & "         Types :" & @CRLF & $sTxt)

_IEQuit($oIE)

EndFunc

 

Link to post
Share on other sites

Try this :

#include <Constants.au3>
#include <GUIConstants.au3>
#include <IE.au3>

Opt ("MustDeclareVars", 1)

HotKeySet("{esc}", "_Exit")
func _Exit()
    Exit
EndFunc


Global $oIE = _IECreate("http://www.lycee-champblanc.net/resa.php")
WinSetState(_IEPropertyGet($oIE,"hwnd"),"",@SW_MAXIMIZE)
_IELoadWait($oIE)
Sleep(2500)

SignIn()

Func SignIn()

  Do
    Local $user = _IEGetObjByName($oIE,"username")
    Local $pwd = _IEGetObjByName($oIE,"password")
    Local $button = _IEGetObjById($oIE,"but_login")

    _IEFormElementSetValue($user,"xxxxxx")
    _IEFormElementSetValue($pwd,"xxxxxxxx")
    _IEAction($button,"click")
    _IELoadWait($oIE)

    _IELoadWait($oIE)
    Sleep(2500)

    Local $sujet1 = _IEDocReadHTML ($oIE)
    Local $refreshornot = "L'identifiant ou le mot de passe saisi est incorrect"

    Local $resultat1 = StringRegExp($sujet1, $refreshornot, $STR_REGEXPMATCH)

  Until $resultat1 = 0

  _IELoadWait($oIE)

  Local $oInputs = _IETagNameGetCollection($oIE, "div")
  Local $sTxt = ""
  For $oInput In $oInputs
    If $oInput.className = "vide" or $oInput.className = "" then ContinueLoop
    If StringLeft ($oInput.className,5) = "table" then
      $sTxt &= $oInput.className & " " & $oInput.innerText & @CRLF
    endif
  Next
  MsgBox (0,"",$sTxt)

  _IEQuit($oIE)

EndFunc

Works for me :)

Link to post
Share on other sites
39 minutes ago, HugoNatalis said:

my code to catch and click the objet I want is not working.

Add some error checking/handling.

Almost every _IE* function (and not) sets a code called @error to a non-zero value if an error occurs.

You can check that value after calling a specific function, something like:

_IECreate("URL")
If @error Then
    ; Handle the error
Else
    ; Go ahead with the script
EndIf

Doing this helps you a lot since you can see where your script is failing, and so, making your script works :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...