2016-10-28 6 views
0

私はセレンのVBAでページを開いています。このページには同じクラス名の要素がたくさんあります。コード:People = driver.findElementByClass("labelinfo").Textそれは私のページに最初の要素を返し、私はコードを使用するので、私はコードを使用します:driver.findElementsByClassName("labelinfo").Countとそれは27要素 "labelinfo"を持っていると言う。では、要素番号7に達するまでforループを使って要素を要素ごと "歩く"ことができますか? 私のコードは次のとおりです。セレンのvbaを使って同じクラス名のページの次の要素に移動する方法

Public Sub AbreELogaNoForum() 
    Dim i As Integer, MyPass As String, MyLogin As String, nome As String, data As String, carteira As String, guia As String, test As Long 

    Application.ScreenUpdating = False 
redo: 
    MyLogin = Application.InputBox("Por Favor entre com o Login") 
    MyPass = Application.InputBox("Por favor entre com a senha") 
    If MyLogin = "" Or MyPass = "" Then GoTo redo 
    driver.Start "chrome", "http://rda.unimednc.com.br/" 
    driver.setImplicitWait 50000 

    driver.Open "http://rda.unimednc.com.br/" 
    driver.findElementById("login").SendKeys MyLogin 
    driver.findElementById("password").SendKeys MyPass 
    driver.findElementById("Button_DoLogin").Click 

    test = 7 
    Range("B1").Select 
    For i = 1 To 10 
    MsgBox ("Esperando") 
    'nome = driver.findElementByClass("labelinfo").Text 
    ActiveCell.Value = driver.findElementsByClassName("labelinfo").Count 
    ActiveCell.Offset(1, 0).Select 
    Next 

End Sub 

Public Sub FechaBrowser() 
    driver.stop 
End Sub 

答えて

0

あなたが特定の要素にしたいように見えます:

Dim oElementLooked as WebElement 
set oElementLooked = driver.findElementsByClassName("labelinfo").Item(7) 

あなたが回答をループしたい場合は、あなたが何かを行うことができます:

Dim colNodes as WebElements 
Dim oElementLooked as WebElement 
set colNodes = driver.findElementsByClassName("labelinfo") 
for each oElementLooked in colNodes 
    ' Your code here 
Next oElementLooked 

youdはループするためにitemとcounterを使うこともできることに注意してください。

関連する問題