leochabi / selenium-vba

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

Using variable inside gettext() #38

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system :win 7
.Net Framework version : latest
Office Version :2007
SeleniumWrapper version :last

What is your issue ?
Hello,
Im trying to pass the counter variable i inside 
selenium.getText("//html/body/div[2]/div[2]/div[2]/div/div/div/div[""i""]")

but its only getting correct for the 1st time and not incrementing inside 
gettext() 

Im using for loop ,please check the following code and help.

Dim selenium
Dim ok
Set selenium = CreateObject("SeleniumWrapper.WebDriver")
selenium.start "firefox", "http://www.wikihow.com/"
selenium.setImplicitWait 5000

selenium.open "/Make-Money"
For i=1 To 5
  MsgBox(i)
  ok = selenium.getText("//html/body/div[2]/div[2]/div[2]/div/div/div/div[""i""]")
  MsgBox (ok)
Next
MsgBox "Done"

selenium.stop

Original issue reported on code.google.com by shan4sha...@gmail.com on 30 Dec 2013 at 12:41

GoogleCodeExporter commented 8 years ago
First, your VBA syntax is incorrect. It should be like this:
ok = selenium.getText("//html/body/div[2]/div[2]/div[2]/div/div/div/div[" & i & 
"]")

Second, I recommend you to use a CSS selector rather than an XPath and to 
search all the web elements in one command for better performance. I would do 
something like this :

    Dim methods As WebElementCollection
    Set methods = selenium.findElementsByCssSelector("div.section.steps")
    For i = 0 To methods.Count - 1
        MsgBox methods(i).Text
    Next

Original comment by florentbr on 1 Jan 2014 at 11:45

GoogleCodeExporter commented 8 years ago

Original comment by florentbr on 8 Sep 2014 at 5:40