Jump to content

AutoIt script <Div class> search


Recommended Posts

Hello all I have been lurking on this forum for a bit and have search nearly all the support threads around a script to read a webpage, input data, and click on a button.  I was wonder if someone can help connect the dots for me on my code.   The problem I have is with a website that has this class tag.  <div class="uiButton-label">Mail</div>  See attached image of the website code. 

The first part of my code works fine.   It input the username and password and hit the login in button.

 

Block 1 - This one is just the input of the username and password and click on login button.  (working)

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

 #include <IE.au3>

;~ Connect to the site
Local $oIE = _IECreate("my website ", 1)
;~ Wait for the site to load
_IELoadWait($oIE)
;~ Get all Inputs
Local $oInputs = _IETagNameGetCollection($oIE, "Input")
For $oInput In $oInputs
    ;~ Fill in Username Field
    If $oInput.id = 'username' Then $oInput.value = 'Your ID'
    ;~ Fill in Password Field
    If $oInput.id = 'password' Then $oInput.value = 'Your Password'

Next
;~ Get all Buttons
Local $oButtons = _IETagNameGetCollection($oIE, "Button")
For $oButton In $oButtons
    ;~ Check if Button InnerText equals Log In and perform an action.
    ;~ Uncomment the _IEAction line below to submit the form.
    If $oButton.id = 'Login' Then
        MsgBox(64, 'Log In Button Found', 'Button found with value: ' & $oButton.InnerText)
        _IEAction($oButton, 'click')
    EndIf
Next

 

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

 

 

Block 2 -  The code below is actually part of the block 1 code. I just broke this up for better visual.   The problem here is I'm thinking it's not able to find the class 'Mail'.  From the attachment it's labeled.  The site has label this as <div class= "uiButton-label">Mail</div>.   I even try the full class name and it did work.  I can use "uiButton-label cause there are other similar buttons with this label.  Example is  another div call called   <div class='uiButton-Lable">Packages</div>.  If this is not the solution to use then any recommendation is greatly appreciated. 

 

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

;~ Wait for the site to load
_IELoadWait($oIE)
;locate Mail button
Local $oMails = _IETagNameGetCollection($oIE, "Div")
For $oMail in $oMails
    ;~Check for mail
    If $oMail.class = 'Mail' Then
        MsgBox(64, 'Mail found', 'Mail found with value: ' & $oMail.InnerText)
        _IEAction($oMail, 'click')
    EndIf
Next

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

Capture.JPG

Link to comment
Share on other sites

1 minute ago, Stunnas said:

From the attachment it's labeled.  The site has label this as <div class= "uiButton-label">Mail</div>.   I even try the full class name and it did work.  I can use "uiButton-

Sorry i had a typo on my post.  I mean "I even try the full class name and It DIDN"T work".  

Link to comment
Share on other sites

Try this:

$oDoc = _IEDocGetObj($oIE)
    $oElement = _IEquerySelectorAll($oDoc, "#nav-bar div.uiButton-label", 0)


 

 

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Ok I think I see the problem.  Once I log into the website.  The URL path name doesn't change so when its looking for the mail tag its not finding it because it still thinks its on the log on page.  This is me theorizing my problem. 

The URL is https://us1.aconex.com/Logon   once i logged in it remains the same but I see a whole new set of data on the page.  So if i'm understanding the script It's trying to read the the same URL which doesn't have the tag i'm looking for.  Is there a script to read the current page?   I'm not sure if i'm making any sense here. 

Local $oIE = _IECreate("https://us1.aconex.com/Logon ", 1)    So $oIE = https://us1.aconex.com/Logon    

 

Link to comment
Share on other sites

I see a few problems with your code :

1- _IELoadWait($oIE) may not wait for all portions of the page to be loaded.  It is possible (I saw that before) that partial page is displayed and some other will be shown later.  So what you need to do is look at a specific element that is appearing only when the full page is loaded.  Just create a loop that is searching for it.

2- If $oMail.class = 'Mail' Then is wrong based on the DOM you posted.  It is innerText instead of class.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...