2017-07-29 208 views
2

嘗試了下面的代碼以下URL Scripture look up。請如何將下拉值從WEB更改爲RV1909VBA IE更改下拉值

Dim Doc As HTMLDocument 
Set Doc = IEApp.document 

TestV2 = "" 
TestV3 = "" 

TestV2 = Doc.getElementsByClassName("app-list text-list")(0).innerText 
Debug.Print "4b of 5: " & TestV2  

IEApp.Doc.getElementsByClassName("app-list text-list").selectedIndex = 1 
IEApp.Doc.getElementsByClassName("app-list text-list").FireEvent ("onchange") 

TestV3 = Doc.getElementsByClassName("app-list text-list")(0).innerText 
Debug.Print "4c of 5: " & TestV3 
從其他職位

試過許多方法,下面不工作:

IEApp.Doc.getElementsByClassName("app-list text-list")(0).innerHTML = "RV1909" 

這裏是Chrome檢查的截圖:

Screenshot of Chrome Inspector

回答

1

在這種情況下,僅僅更改div.app-list.text-list元素innerText是不夠的,因爲您可以看到元素很簡單div,但甚至不是ul。它應該通過在click事件上調用的腳本進行更改。所以,首先你需要點擊div來顯示整個列表,然後點擊RV1909項目。下面的例子演示瞭如何可以做:

Sub Test() 

    Dim oIE As Object 
    Dim oDiv As Object 

    Set oIE = CreateObject("InternetExplorer.Application") 
    With oIE 
     .Visible = True 
     .Navigate "http://ebible.org/study/" 
     Do While .readyState <> 4 Or .Busy 
      DoEvents 
     Loop 
     With .Document 
      Do While .readyState <> "complete" 
       DoEvents 
      Loop 
      Set oDiv = .getElementsByClassName("app-list text-list")(0) 
      oDiv.Click 
      Do While .readyState <> "complete" 
       DoEvents 
      Loop 
      For Each oNode In .getElementsByClassName("text-chooser-main")(0).getElementsByClassName("text-chooser-abbr") 
       If oNode.innerText = "RV1909" Then 
        oNode.Click 
        Do While oDiv.innerText <> "RV1909" 
         DoEvents 
        Loop 
        Exit For 
       End If 
      Next 
     End With 
    End With 

End Sub 
+0

謝謝您的解決方案。 –

0

更改HTML div元素<div class=app-list text-list>WEB</div><div class=app-list text-list>RV1909</div>

+0

請,我將如何修改這個改變DIV IEApp.Doc.getElementsByClassName(「應用列表文本列表」)(0).value的= 「RV1909」 –

+0

嘗試了其他帖子的很多方法,以下不起作用: IEApp.Doc.getElementsByClassName(「app-list text-list」)(0).innerHTML =「RV1909」 –