Jump to content
oemript

How to retrieve the link location using AutoIT?

Recommended Posts

oemript

Referring to following image, I would like to know on how to display the link location using AutoIT and display on MsgBox as shown below

https://www.testing.com/catalog/?q=toys

Click_Link1.png

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

Edited by oemript

Share this post


Link to post
Share on other sites
Earthshine

this is a gimme deh codez post I guess. :(

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Subz

@oemript I've provided several pieces of code for you, you should be able to create the code for this by utilizing that code

Hints

  1. _IETagNameGetCollection "div"
  2. Check "div" tag object has ClassName for navigation bar
  3. _IETagNameGetCollection "a" tag within the "div" object found from step 2 above
  4. Enumerate the "a" tag objects and collect the href property for the address, example $sAddress = $a.href

At least attempt to put the code together and if you get stuck then post what you have attempted.

Share this post


Link to post
Share on other sites
oemript

Generally, I briefly describe on following coding, but don't know what coding can locate specific items as shown below:

Click_Link2.png

Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys")
Local $oListBoxs = _IETagNameGetCollection($oIE, "div")
Local $sSearch = ""
For $oListBox In $oListBoxs
    If data-qa-locator="general-products" Then
        $oListItems = _IETagNameGetCollection($oListBox, "div")
        For $oListItem In $oListItems
            If data-qa-locator="product-item" Then
                Retrieve the attribute "data-spm-anchor-id" and display on MsgBox "a2o4k.searchlist.list.i0.2cd1683dJYIaTp"
                ExitLoop 2
            EndIf
        Next
    EndIf
Next
MsgBox(32, "data-spm-anchor-id", $ID )

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Edited by oemript

Share this post


Link to post
Share on other sites
Subz

Close:

#include <IE.au3>

Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys", 1)
Local $oListBoxs = _IETagNameGetCollection($oIE, "div")
Local $sSearch = ""
For $oListBox In $oListBoxs
    If $oListBox.getAttribute("data-qa-locator") ="general-products" Then
        $oListItems = _IETagNameGetCollection($oListBox, "a")
        For $oListItem In $oListItems
            If StringStripWS($oListItem.InnerText, 8) <> "" Then MsgBox(32, "List Item", "Item Information: " & @CRLF & $oListItem.InnerText & @CRLF & @CRLF & "Item Address: " & @CRLF & $oListItem.href)
        Next
    EndIf
Next

 

Share this post


Link to post
Share on other sites
oemript
2 hours ago, Subz said:

 

#include <IE.au3>

Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys", 1)
Local $oListBoxs = _IETagNameGetCollection($oIE, "div")
Local $sSearch = ""
For $oListBox In $oListBoxs
    If $oListBox.getAttribute("data-qa-locator") ="general-products" Then
        $oListItems = _IETagNameGetCollection($oListBox, "a")
        For $oListItem In $oListItems
            If StringStripWS($oListItem.InnerText, 8) <> "" Then MsgBox(32, "List Item", "Item Information: " & @CRLF & $oListItem.InnerText & @CRLF & @CRLF & "Item Address: " & @CRLF & $oListItem.href)
        Next
    EndIf
Next

Please see the following image, it requires a click action, the link are different as shown below

Click_Link3.png

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Edited by oemript

Share this post


Link to post
Share on other sites
Earthshine

look into IUIAutomation

You don’t appear to try anything on your own. Do you have any suggestions?

Edited by Earthshine
  • Like 1

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
oemript

I would like to know on following issues

1) Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys"), how to maximize the IE window through coding?

2) Which function would move mouse coordination into specific location?

3) How to display the current mouse coordination as shown on following image "(Frogen) AutoIt v3 Window Info"?

Click_Link4.png

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

Edited by oemript

Share this post


Link to post
Share on other sites
Subz

The following code will work but not 100% sure why it doesn't open a new tab instance, although it does get the session information.

a1. WinSetState (see code)

a2. MouseClick or ControlClick

a3. MouseGetPos

Its all in the help file.

#include <IE.au3>

Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys", 1)
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
Local $oListBoxs = _IETagNameGetCollection($oIE, "div")
Local $sSearch = "", $sLocationUrl = ""
For $oListBox In $oListBoxs
    If $oListBox.getAttribute("data-qa-locator") ="general-products" Then
        $oListItems = _IETagNameGetCollection($oListBox, "a")
        For $oListItem In $oListItems
            If StringStripWS($oListItem.InnerText, 8) <> "" Then
                _IEAction($oListItem, "focus")
                Send("{CTRLDOWN}")
                ControlClick(_IEPropertyGet($oIE, "title"), $oListItem.InnerText, "")
                Send("{CTRLUP}")
                MsgBox(32, "List Item", "Item Information: " & @CRLF & $oListItem.InnerText & @CRLF & @CRLF & "Item Address: " & @CRLF & $oListItem.href)
            EndIf
        Next
    EndIf
Next

 

Share this post


Link to post
Share on other sites
oemript

Is there any debug feature within AutoIt to run line by line and check on what variable gets?

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Share this post


Link to post
Share on other sites
Earthshine

Subs. Why do you bother with this one?  Not worth responding to at all. Here to just use you

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
oemript

Please see following image, there is an error as shown below

Click_Link5.png

Another approach, the following code clicks on the first item based on mouse coordination, and then would it be possible to retrieve the URL within URL bar?

#include <IE.au3>
Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys", 1)
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
Sleep(3000)
MouseClick($MOUSE_CLICK_LEFT, 300, 500, 1)
Sleep(3000)

Click_Link6.png

Do you have any suggestions on the error message? or if another approach would be easier, how to retrieve URL within URL bar?
Thanks, to everyone very much for any suggestions (^v^)

Edited by oemript

Share this post


Link to post
Share on other sites
oemript

For Firefox, when I do following action manually, the session is triggered, but not for IE.

1) Mouse_Click_Right

2) MouseClickDrag

Does anyone have any suggestions on what wrong IE is?

Would it be possible to use FireFox to open browser instead of IE under AutoIT script?
Thanks, to everyone very much for any suggestions (^v^)

 

Edited by oemript

Share this post


Link to post
Share on other sites
oemript

It seems that my IE is not enable AJAX, could anyone please try on following coding to see on whether it works on IE or not?

If it works on IE, then does anyone have any suggestions on how to enable AJAX on IE?
Thanks, to everyone very much for any suggestions (^v^)

 

#include <IE.au3>

Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys", 1)
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
Local $oListBoxs = _IETagNameGetCollection($oIE, "div")
Local $sSearch = "", $sLocationUrl = ""
For $oListBox In $oListBoxs
    If $oListBox.getAttribute("data-qa-locator") ="general-products" Then
        $oListItems = _IETagNameGetCollection($oListBox, "a")
        For $oListItem In $oListItems
            If StringStripWS($oListItem.InnerText, 8) <> "" Then
                _IEAction($oListItem, "focus")
                Send("{CTRLDOWN}")
                ControlClick(_IEPropertyGet($oIE, "title"), $oListItem.InnerText, "")
                Send("{CTRLUP}")
                MsgBox(32, "List Item", "Item Information: " & @CRLF & $oListItem.InnerText & @CRLF & @CRLF & "Item Address: " & @CRLF & $oListItem.href)
            EndIf
        Next
    EndIf
Next

 

Share this post


Link to post
Share on other sites
oemript

Hi Subz:

When I manually click and drag the product image, for firefox, this action can trigger session, but for IE, session cannot be triggered on my IE.

Could you please test the following code again on your IE to see on whether session can be triggered or not?

#include <IE.au3>

Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys", 1)
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
Local $oListBoxs = _IETagNameGetCollection($oIE, "div")
Local $sSearch = "", $sLocationUrl = ""
For $oListBox In $oListBoxs
    If $oListBox.getAttribute("data-qa-locator") ="general-products" Then
        $oListItems = _IETagNameGetCollection($oListBox, "a")
        For $oListItem In $oListItems
            If StringStripWS($oListItem.InnerText, 8) <> "" Then
                _IEAction($oListItem, "focus")
                Send("{CTRLDOWN}")
                ControlClick(_IEPropertyGet($oIE, "title"), $oListItem.InnerText, "")
                Send("{CTRLUP}")
                MsgBox(32, "List Item", "Item Information: " & @CRLF & $oListItem.InnerText & @CRLF & @CRLF & "Item Address: " & @CRLF & $oListItem.href)
            EndIf
        Next
    EndIf
Next

I am using IE v11.09600.18920

Thank you very much for any suggestions (^v^)

Share this post


Link to post
Share on other sites
Subz

Using 11.2068.14393.0 - WIndows 10 x64 Enterprise the code above works, tested before I posted.  Try using SHIFTDOWN/SHIFTUP instead of CTRLDOWN/CTRLUP as I mentioned it works for my system Ctrl+Click on the "a" tag should trigger Ajax, I get the full url with session, not sure why your system isn't working though.

Share this post


Link to post
Share on other sites
Subz

Try this code, this grabs the information from the statustext which changes each time you change the focus:

#include <IE.au3>

Local $oIE = _IECreate("https://www.lazada.com.my/catalog/?q=toys", 1)
WinSetState(_IEPropertyGet($oIE, "title"), "", @SW_MAXIMIZE)
Local $oListBoxs = _IETagNameGetCollection($oIE, "div")
Local $sSearch = "", $sLocationUrl = ""
For $oListBox In $oListBoxs
    If $oListBox.getAttribute("data-qa-locator") ="general-products" Then
        $oListItems = _IETagNameGetCollection($oListBox, "a")
        For $oListItem In $oListItems
            If StringStripWS($oListItem.InnerText, 8) <> "" Then
                _IEAction($oListItem, "focus")
                MsgBox(32, "List Item", "Item Information: " & @CRLF & $oListItem.InnerText & @CRLF & @CRLF & "Item Address: " & @CRLF & _IEPropertyGet($oIE, "statustext"))
            EndIf
        Next
    EndIf
Next

 

Share this post


Link to post
Share on other sites
oemript

Using IE v11.09600.18920 - Window 7 Home, the code do not work, when IE open with specific URL, I manually press SHIFT DOWN and UP / CTRL DOWN and UP, which cannot trigger session at all, and I also try manually the same task on FireFox, which cannot trigger session as well.

SHIFTDOWN/SHIFTUP

CTRLDOWN/CTRLUP

When I manually mouseclickdrag an image on coordination (300,500) to (0,500), which can trigger session for FireFox, but when I manually do the same task on IE, which cannot trigger session for IE, which seem that IE is not enable for AJAX.

What I find work on IE is mouseclick on (300,500), which would click on the first product image link. After that, it would do directly to specific product's page, and the session is contained withn URL within URL bar as shown below, would it be possible to retrieve the URL within URL bar using AutoIt?

Do you have any suggestions on what is the possible cause for this IE's error? or if another approach would be easier, how to retrieve URL within URL bar?
Thanks, to everyone very much for any suggestions (^v^)

Click_Link6.png

Share this post


Link to post
Share on other sites
Subz

Did you try the code I posted above?

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

×