Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Click on specific object on webpage


Best Answer Jackie Sztuk _Blackholyman , 07 October 2015 - 12:59 PM

Go to the full post »


  • Please log in to reply
7 replies to this topic
zabayek
  • New members
  • 4 posts
  • Last active: Nov 09 2015 12:22 PM
  • Joined: 07 Oct 2015

Hello community. 

 

This is my first post in here.

 

Basicly what I'm trying to do is to click on specific button on webpage: https://wyszukiwarka...pBIR/index.aspx This is polish gov site with info about companies. 

 

- Insert captha

- Paste 690716965 into REGON txtbox, then press "Szukaj"

- Click on Regon number in table bellow (whole information should appear)

- I'd like to click on "rozwiń listę >>" at the bottom of the page. 

 

And now the question guys. Is it possible to click on this element? I was trying to use ie.document.getElementsByTagName("rozwiń listę >>").Click(), but it doesn't work. I'm stuck. 

 

Any ideas?

 

Thanks in advance.

zabayek



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
✓  Best Answer
do the Captcha, then press f3

f3::
wb := WBGet()

wb.document.getElementById("txtRegon").value := 690716965

wb.document.getElementById("btnSzukaj").click()

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ;
	sleep 100

sleep 1000

Div_over_Table := wb.document.getElementById("divListaJednostek")

Table := Div_over_Table.getElementsByTagName("Table")[0]

rows := table.rows

Cells := rows[1].Cells ; second rows cells

Link := cells[0].getElementsByTagName("A")[0]

Link.click()

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ;
	sleep 100

sleep 1000

Div_over_Button := wb.document.getElementById("fiz_linkdzial")

input_button := Div_over_Button.getElementsByTagName("input")[0]

input_button.click()

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ;
	sleep 100
return




WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}

Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

boiler
  • Members
  • 252 posts
  • Last active: Nov 07 2015 09:39 PM
  • Joined: 04 Jun 2014

I don't think "rozwin liste >>" is the actual name of the tag.  TagName refers to the actual HTML tags like "a" or "div".  And if there is more than one, you would need to identify which one, such as getElementsByTagName("a")[9].Click()

 

You might also want to try getElementById the ID would probably more uniquely identify that button.

 

You can always use form[0].element[10] to identify it, and just try different numbers for the element (and form, if necessary) until you find it.  One way to find it is with something like:

Loop
{
    MsgBox, 1, , % ie.document.form[0].element[A_Index]
    IfMsgBox, Cancel
        break
}

(not tested)

 

Edit:  Didn't see Blackholyman's post before I posted.  I'm sure that gets you what you need.



zabayek
  • New members
  • 4 posts
  • Last active: Nov 09 2015 12:22 PM
  • Joined: 07 Oct 2015

do the Captcha, then press f3
 

f3::
wb := WBGet()

wb.document.getElementById("txtRegon").value := 690716965

wb.document.getElementById("btnSzukaj").click()

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ;
	sleep 100

sleep 1000

Div_over_Table := wb.document.getElementById("divListaJednostek")

Table := Div_over_Table.getElementsByTagName("Table")[0]

rows := table.rows

Cells := rows[1].Cells ; second rows cells

Link := cells[0].getElementsByTagName("A")[0]

Link.click()

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ;
	sleep 100

sleep 1000

Div_over_Button := wb.document.getElementById("fiz_linkdzial")

input_button := Div_over_Button.getElementsByTagName("input")[0]

input_button.click()

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ;
	sleep 100
return




WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}

Great! Work like a charm ;)

 

Just two more questions:

- As I have noticed, this element "fiz_linkdzial" sometimes is named as "fiz_linkdzial", but sometimes as "praw_linkdzial" (i.e. in regon no. 012172810). Is it possible for your script to work with both of them, according to the one used on website? 

 

- For this captcha image - is it possible to store this img as a file on the hdd?

 

 

 

zabayek



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
seems like the Captcha element has the ID = "imgCaptch" and the src attribute holds a downloadable url

Untested
URL := wb.document.getElementById("imgCaptch").src
urldownloadtofile, %URL%, TEMP_captcha.bmp
did not look into the other thing much

but you may be able to simply use the classname "button5"

input_button := wb.document.getElementsByClassName("button5")[0]
Hope it helps
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

zabayek
  • New members
  • 4 posts
  • Last active: Nov 09 2015 12:22 PM
  • Joined: 07 Oct 2015

Thank you both guys. 

 

Issue solved.



zabayek
  • New members
  • 4 posts
  • Last active: Nov 09 2015 12:22 PM
  • Joined: 07 Oct 2015

Jackie,

 

just one more question. I did some research but now I'm stuck:

how to store in variables text elements of this page i.e. NIP which is 8131960644? I know that it has id: fiz_regon9. Or nazwa which is GOSPODARSTWO ROLNE PIĄTEK WITOLD (id fiz_nazwa), and other elements on that page.

 

I was trying ie.document.getElementsById("fiz_regon9").Value but I probably made some mistake, because it doesn't work.

 

Thanks in advance,

Pawel



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
You have an s in getElementById try and Remove that
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About