VineGlobal / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
1 stars 0 forks source link

get href link and count tags [not working for me] #101

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Operating system and version (32/64bit) :64
.Net Framework version :4
Office name and version(32/64bit) :64
Browser name and version :firefox
SeleniumWrapper version :latest

What steps will reproduce the problem with a public website ?
how can i write this in VBA 
document.getElementsByTagName('table')[5].getElementsByTagName('a').length;

in the HTML below: 

<a href="/sserv/casedetailview.jsp?id=5008000000b4P4Q">iPad Initial Sync - 
Taking a long time</a>

i am trying to retrieve the value in href 

I am unable to do:

document.getElementsByTagName('table')[5].getElementsByTagName('a')[4].getAttrib
ute('href')

I get the error : object does not support this property or method

Can you please help

Original issue reported on code.google.com by alam...@gmail.com on 6 Oct 2014 at 7:28

GoogleCodeExporter commented 9 years ago
The error "object does not support this property or method" is because VBA 
doesn't  know what "[4]" is. To select an element in an array in VBA, you need 
to use parenthesis.

A correct syntax would be:
document.getElementsByTagName('table')(5).getElementsByTagName('a')(4).getAttrib
ute('href')

But this is not recommended as it implies multiple calls and unnecessary data 
are imported.
A better syntax would be to use XPath (:
document.getElementsByXPath('//table[5]//a[4]').getAttribute('href')

Original comment by florentbr on 7 Oct 2014 at 6:11

GoogleCodeExporter commented 9 years ago
Great , thanks a lot , what about the first question please:

how can i write this in VBA 
document.getElementsByTagName('table')[5].getElementsByTagName('a').length;

I want to count how many tagname 'a' exist in table(5)

Thanks a lot again :)

Original comment by alam...@gmail.com on 7 Oct 2014 at 8:13

GoogleCodeExporter commented 9 years ago
len = document.getElementsByXPath('//table[5]//a').Count

Original comment by florentbr on 7 Oct 2014 at 10:40