Dim ebay As HtmlDocument = WebEBay.Document ‘宣告物件
Dim dhl As HtmlDocument = WebDHL.Document
Dim dhl As HtmlDocument = WebDHL.Document
ebay.GetElementById("sellernotes").GetAttribute("value") ‘取得元素值
ebay.GetElementsByTagName("a").Count ‘文件中<a>的總數
ebay.GetElementsByTagName("a").Item(i).GetAttribute("href") ‘第i個<a>
dhl.GetElementById("txtCompanyName").SetAttribute("value", TheValue) ‘設定元素內的值
Dim TheLength As Integer = ebay.All.Count ‘取得整份文件長度
範例:某個元素內包含的文字
If TheEmailAddress = "" Then
For i = 0 To ebay.GetElementsByTagName("td").Count – 1
If ebay.GetElementsByTagName("td").Item(i).InnerText = "Buyer Email" Then
TheEmailAddress = ebay.GetElementsByTagName("td").Item(i + 1).InnerText
Exit For
End If
Next
End If
For i = 0 To ebay.GetElementsByTagName("td").Count – 1
If ebay.GetElementsByTagName("td").Item(i).InnerText = "Buyer Email" Then
TheEmailAddress = ebay.GetElementsByTagName("td").Item(i + 1).InnerText
Exit For
End If
Next
End If
範例:觸發元素內的事件
Dim InputList As HtmlElementCollection = dhl.GetElementsByTagName("input")
For i = 0 To InputList.Count – 1
With InputList.Item(i)
If .GetAttribute("type") = "radio" And .GetAttribute("name") = "dropoff" And .GetAttribute("value") = "1" Then
.SetAttribute("checked", "true")
.RaiseEvent("onclick")
Exit For
End If
End With
Next
For i = 0 To InputList.Count – 1
With InputList.Item(i)
If .GetAttribute("type") = "radio" And .GetAttribute("name") = "dropoff" And .GetAttribute("value") = "1" Then
.SetAttribute("checked", "true")
.RaiseEvent("onclick")
Exit For
End If
End With
Next
dhl.InvokeScript("setPickup") ‘呼叫文件內的Script
範列
Dim dhl As HtmlDocument = WebDHL.Document
If dhl.GetElementById("dbxSvcType").GetAttribute("selectedindex") <> 5 Then
If MsgBox("Not ship via Ground , Continue?", MsgBoxStyle.YesNo, "Warning") = MsgBoxResult.No Then Exit Sub
End If
dhl.InvokeScript("goForward_onNext", New String() {"document.frmShipment"})
If dhl.GetElementById("dbxSvcType").GetAttribute("selectedindex") <> 5 Then
If MsgBox("Not ship via Ground , Continue?", MsgBoxStyle.YesNo, "Warning") = MsgBoxResult.No Then Exit Sub
End If
dhl.InvokeScript("goForward_onNext", New String() {"document.frmShipment"})
沒有留言:
張貼留言