junche4 / selenium-vba

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

how to get innertext or textcontent with selenium #126

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Operating system :
.Net Framework version :4.5
Office Version :2013
SeleniumWrapper version :last

What is your issue ?

hello, 

how can I write this in selenium:

document.getElementsByClassName('classname1')[0].innerText

I have tried like this:

Range("A5") = driver.findElementByClassName("classname1")(0).Text

but I got the error on the screenshot.

Can you please help, thanks :)

Original issue reported on code.google.com by alam...@gmail.com on 19 Dec 2014 at 3:38

Attachments:

GoogleCodeExporter commented 9 years ago
Basically, I am trying here to get article1 from this html:

<span autoid="_lv_5" class="classname1">article1</span>
<span autoid="_lv_5" class="classname1">article2</span>
<span autoid="_lv_5" class="classname1">article3</span>

Original comment by alam...@gmail.com on 19 Dec 2014 at 3:42

GoogleCodeExporter commented 9 years ago
> document.getElementsByClassName('classname1')[0].innerText
Incorrect: In VBA the square brackets are only used to select a range: 
Sheets(1).[A1]

> Range("A5") = driver.findElementByClassName("classname1")(0).Text
Incorrect: You are trying to get an item from a collection but the 
findElementByClassName returns a WebElement and not a collection

A correct syntax would be:
Debug.Print driver.findElementByClassName("classname1").Text
Or
Debug.Print driver.getElementsByClassName("classname1")(0).Text
Or
Debug.Print driver.getElementsByClassName("classname1").Item(0).Text
Or
For Each e In driver.getElementsByClassName("classname1")
   Debug.Print e.Text
Next

Original comment by florentbr on 19 Dec 2014 at 6:57