Sign in to follow this  
Followers 0
pallavi

IE handling

3 posts in this topic

Hii All,

Am New to Auto it ; i am trieng to browse webpages using auto it. i want to click on perticular link in the webpage.. If i use _IELinkGetCollection() it will gives more than 100 links..

if i use below code

$sMyString = "jewellery"

$oLinks = _IELinkGetCollection($oIE)

For $oLink in $oLinks

$sLinkText = _IEPropertyGet($oLink, "innerhtml")

If StringInStr($sLinkText, $sMyString) Then

_IEAction($oLink, "click")

ExitLoop

EndIf

Next

there are more than 50 links contains word "jewellery" I need only perticular links to click...

i want to click : Jewellery Chola in the below source code.....

<table width='100%' cellpadding=0 cellspacing=0 border=0 width='100%'>

<tr><td height='10px' colspan=3 ></td></tr>

<tr><td width='10'></td><td align='left' colspan='2' class='popsearchfont' ><a href="java script:showdetails('044P9312369','','','');" class='popsearchfont'><span class='popsearchfont'><B>Jewellery Chola</B></span></a><span class='fontblack'></td></tr>

<tr><td height=4 colspan='3' ></td></tr>

<tr><td width='10'></td><td valign='top'></td><td><table width='100%'><tr><td class='txtsub' valign=top>Location</td>

<td class='txtsub' valign='top'>-</td>

<td class='font111' style='padding-left:5' width='80%'>Mylapore,&nbsp;Chennai-600004<span class='font111'></span></td></tr></span>

<tr><td height=4 colspan='3'></td></tr><tr><td class='txtsub' valign=top >Also See </td>

<td class='txtsub' valign='top'>-</td>

<td class='font111' style='padding-left:5' width='80%' id='seealso' ><a HREF="java script:get_company('3753##Diamond Merchants')" class='font111' style='text-decoration:none' onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">Diamond Merchants</a>, <a HREF="java script:get_company('##')" class='font111' style='text-decoration:none' onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'"></a></td></tr>

<tr><td height=10 colspna='3'></td></tr><tr><td></td><td colspan='2'></td></tr><tr><td height=2 colspan='3'></td></tr></table></td>

</table>

i attached my script........ Can any one helps me ???

myscript.txt

Share this post


Link to post
Share on other sites



Hii All,

Am New to Auto it ; i am trieng to browse webpages using auto it. i want to click on perticular link in the webpage.. If i use _IELinkGetCollection() it will gives more than 100 links..

if i use below code

$sMyString = "jewellery"

$oLinks = _IELinkGetCollection($oIE)

For $oLink in $oLinks

$sLinkText = _IEPropertyGet($oLink, "innerhtml")

If StringInStr($sLinkText, $sMyString) Then

_IEAction($oLink, "click")

ExitLoop

EndIf

Next

there are more than 50 links contains word "jewellery" I need only perticular links to click...

i want to click : Jewellery Chola in the below source code.....

<table width='100%' cellpadding=0 cellspacing=0 border=0 width='100%'>

<tr><td height='10px' colspan=3 ></td></tr>

<tr><td width='10'></td><td align='left' colspan='2' class='popsearchfont' ><a href="java script:showdetails('044P9312369','','','');" class='popsearchfont'><span class='popsearchfont'><B>Jewellery Chola</B></span></a><span class='fontblack'></td></tr>

<tr><td height=4 colspan='3' ></td></tr>

<tr><td width='10'></td><td valign='top'></td><td><table width='100%'><tr><td class='txtsub' valign=top>Location</td>

<td class='txtsub' valign='top'>-</td>

<td class='font111' style='padding-left:5' width='80%'>Mylapore,&nbsp;Chennai-600004<span class='font111'></span></td></tr></span>

<tr><td height=4 colspan='3'></td></tr><tr><td class='txtsub' valign=top >Also See </td>

<td class='txtsub' valign='top'>-</td>

<td class='font111' style='padding-left:5' width='80%' id='seealso' ><a HREF="java script:get_company('3753##Diamond Merchants')" class='font111' style='text-decoration:none' onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">Diamond Merchants</a>, <a HREF="java script:get_company('##')" class='font111' style='text-decoration:none' onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'"></a></td></tr>

<tr><td height=10 colspna='3'></td></tr><tr><td></td><td colspan='2'></td></tr><tr><td height=2 colspan='3'></td></tr></table></td>

</table>

i attached my script........ Can any one helps me ???

So why didn't you just use $sMyString = "Jewellery Chola" for your test?

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

So why didn't you just use $sMyString = "Jewellery Chola" for your test?

:mellow:

i think the text you are trying to match is not in the link but related to the link in a table

don't let the code below scare you.. it is mostly all comments etc..

CODE
#include <Array.au3> ; only to display your results for testing

#include <IE.au3>

;the following two lines and the _loadtestpage() function simply load a test page based on the code you supplied

local $oIE = _IECreate("www.google.com")

_loadtestpage($oIE)

local $sMyString = "Jewellery Chola"

local $oTables = _IETableGetCollection ($oIE) ; first we get the tables in our page..

local $oLinks = _IELinkGetCollection ($oIE) ;and the links

; then we loop through our tables .. bear in mind that tables are usually nested in one another so we will need to accomadate for this

local $iTable = 0 ; to keep a track of the table instance

For $oObject in $oTables

local $oTable = _IETableGetCollection ($oIE , $iTable ) ; and get each table in our colection one by one

;this finds four tables... 2 master tables each with an embedded table

local $aTableData = _IETableWriteToArray ($oTable) ; read the data from each table into a 2d array

;~ take a look at the array for testing

;~ _ArrayDisplay($aTableData)

; notice how the text we want to match is in in a particular row and colunm col 1 and row 1

; so only want to look at tables that match these dimensions..

if UBound($aTableData) == 3 and UBound($aTableData,2) == 4 Then

if $aTableData[1][1] = $sMyString then

; now $i is the index of table with the link we need to index the links

; on most sites, links will have something uniuqe about them that we can use to filter and create a index

; you may have to figure out what you can make work depending your sites source code... etc

; In this case i found the link has a unique href i can use that only appears in links in the table i am indexing

;you can use many things such as $olink.innertext and $olink.innerhtml etc

local $iLink = 0 ; counts the number of times the link matches our criteria

for $oLink in $oLinks

; the number of times this statement = true sis also the number of table's with this particular link

if StringInStr ($oLink.href, 'script:get_company' ) <> 0 then

if $iLink == $iTable then ;if the link index is equal to the table index it is the one we want

; your code to click on this link would go here

_Function_to_do_something($oIE,$oLink)

EndIf

$iLink += 1

EndIf

next

EndIf

EndIf

$iTable += 1

Next

func _Function_to_do_something($oIE,$oLink)

MsgBox (0,0,'clicking on link :'&$oLink.innertext &@CRLF &'with URL:'&$oLink.href)

;~ _IEAction($oLink,'click')

; when you click on the link unless the link opens a popup the script will no longer be able to click on the other links

;~ _IELoadWait($oIE)

EndFunc

Func _loadtestpage($oIE)

local $html = ''

;table that does not match

$html &= '<table width="100%" cellpadding=0 cellspacing=0 border=0 width="100%">'

$html &= '<tr><td height="10px" colspan=3 ></td></tr>'

$html &= '<tr><td width="10"></td><td align="left" colspan="2" class="popsearchfont" >'

$html &= '<span class="popsearchfont"><B>GOLD</B></span></a><span class="fontblack"></td></tr>'

$html &= '<tr><td height=4 colspan="3" ></td></tr>'

$html &= '<tr><td width="10"></td><td valign="top"></td><td><table width="100%"><tr><td class="txtsub" valign=top>Location</td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%">Mylapore,&nbsp;Chennai-600004<span class="font111"></span></td></tr></span>'

$html &= '<tr><td height=4 colspan="3"></td></tr><tr><td class="txtsub" valign=top >Also See </td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%" id="seealso" >'

$html &= '<a HREF="java script:get_company("3753##GOLD Merchants")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none"">'

$html &= 'GOLD Merchants</a>, <a HREF="java script:get_company("##")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none""></a></td></tr>'

$html &= '<tr><td height=10 colspna="3"></td></tr><tr><td></td><td colspan="2"></td></tr><tr><td height=2 colspan="3"></td></tr></table></td>'

$html &= '</table>'

;~ table that matches

$html &= '<table width="100%" cellpadding=0 cellspacing=0 border=0 width="100%">'

$html &= '<tr><td height="10px" colspan=3 ></td></tr>'

$html &= '<tr><td width="10"></td><td align="left" colspan="2" class="popsearchfont" >'

$html &= '<span class="popsearchfont"><B>Jewellery Chola</B></span></a><span class="fontblack"></td></tr>'

$html &= '<tr><td height=4 colspan="3" ></td></tr>'

$html &= '<tr><td width="10"></td><td valign="top"></td><td><table width="100%"><tr><td class="txtsub" valign=top>Location</td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%">Mylapore,&nbsp;Chennai-600004<span class="font111"></span></td></tr></span>'

$html &= '<tr><td height=4 colspan="3"></td></tr><tr><td class="txtsub" valign=top >Also See </td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%" id="seealso" >'

$html &= '<a HREF="java script:get_company("3753##Diamond Merchants")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none"">'

$html &= 'Diamond Merchants</a>, <a HREF="java script:get_company("##")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none""></a></td></tr>'

$html &= '<tr><td height=10 colspna="3"></td></tr><tr><td></td><td colspan="2"></td></tr><tr><td height=2 colspan="3"></td></tr></table></td>'

$html &= '</table>'

;~ another table that matches

$html &= '<table width="100%" cellpadding=0 cellspacing=0 border=0 width="100%">'

$html &= '<tr><td height="10px" colspan=3 ></td></tr>'

$html &= '<tr><td width="10"></td><td align="left" colspan="2" class="popsearchfont" >'

$html &= '<span class="popsearchfont"><B>Jewellery Chola</B></span></a><span class="fontblack"></td></tr>'

$html &= '<tr><td height=4 colspan="3" ></td></tr>'

$html &= '<tr><td width="10"></td><td valign="top"></td><td><table width="100%"><tr><td class="txtsub" valign=top>Location</td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%">Mylapore,&nbsp;Chennai-600004<span class="font111"></span></td></tr></span>'

$html &= '<tr><td height=4 colspan="3"></td></tr><tr><td class="txtsub" valign=top >Also See </td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%" id="seealso" >'

$html &= '<a HREF="java script:get_company("3753## Merchants")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none"">'

$html &= 'Jade Merchants</a>, <a HREF="java script:get_company("##")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none""></a></td></tr>'

$html &= '<tr><td height=10 colspna="3"></td></tr><tr><td></td><td colspan="2"></td></tr><tr><td height=2 colspan="3"></td></tr></table></td>'

$html &= '</table>'

;~ another table that does not match

$html &= '<table width="100%" cellpadding=0 cellspacing=0 border=0 width="100%">'

$html &= '<tr><td height="10px" colspan=3 ></td></tr>'

$html &= '<tr><td width="10"></td><td align="left" colspan="2" class="popsearchfont" >'

$html &= '<span class="popsearchfont"><B>Something else</B></span></a><span class="fontblack"></td></tr>'

$html &= '<tr><td height=4 colspan="3" ></td></tr>'

$html &= '<tr><td width="10"></td><td valign="top"></td><td><table width="100%"><tr><td class="txtsub" valign=top>Location</td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%">Mylapore,&nbsp;Chennai-600004<span class="font111"></span></td></tr></span>'

$html &= '<tr><td height=4 colspan="3"></td></tr><tr><td class="txtsub" valign=top >Also See </td>'

$html &= '<td class="txtsub" valign="top">-</td>'

$html &= '<td class="font111" style="padding-left:5" width="80%" id="seealso" >'

$html &= '<a HREF="java script:get_company("3753## Merchants")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none"">'

$html &= 'Copper Merchants</a>, <a HREF="java script:get_company("##")" class="font111" style="text-decoration:none" '

$html &= 'onmouseover="this.style.textDecoration="underline"" onmouseout="this.style.textDecoration="none""></a></td></tr>'

$html &= '<tr><td height=10 colspna="3"></td></tr><tr><td></td><td colspan="2"></td></tr><tr><td height=2 colspan="3"></td></tr></table></td>'

$html &= '</table>'

_IEBodyWriteHTML($oIE,$html)

EndFunc

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