selenium vba extracting data from web table last bit of code to copy text does not work










3















I have been trying to import the table results from http://avionictools.com/icao.php
using example Reg code is N2
my code adds the Reg code and clicks the submit button , but I am unable to copy the results from the table. I wanted the hex code copying to column C



Public Sub regsearch()
Dim LR1, lr2 As Long, i As Long

LR1 = Sheet1.Range("A" & Rows.Count).End(xlUp).Row



Dim data As String

Dim bot As New WebDriver
For i = 2 To 2
Sheet1.Range("A" & i).Copy 'Value is N2

Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")
With clipboard
.GetFromClipboard
data = .getText
End With
'MsgBox data
bot.Start "chrome", "http://avionictools.com"


bot.Wait 2000
bot.get "/icao.php"
bot.Wait 2000


bot.FindElementByName("data").Click

bot.SendKeys data
bot.Wait 2000
bot.FindElementByXPath("//div/input").Click



bot.Wait 1000


Set Table = bot.getElementsByTagName("table").Item(0)
For Each Tr In Table.getElementsByTagName("tr")
tdlen = Tr.getElementsByTagName("td").Length
If tdlen > 1 Then
lr = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1
Sheet1.Range("C" & i).Value = Tr.getElementsByTagName("td").Item(0).innerText
Sheet1.Range("D" & i).Value = Tr.getElementsByTagName("td").Item(1).innerText
Else

End If


Next Tr
Application.Wait Now + TimeValue("00:00:04")


Next
End Sub









share|improve this question
























  • Did you try my answer? I have added another for your revised question.

    – QHarr
    Nov 26 '18 at 19:00















3















I have been trying to import the table results from http://avionictools.com/icao.php
using example Reg code is N2
my code adds the Reg code and clicks the submit button , but I am unable to copy the results from the table. I wanted the hex code copying to column C



Public Sub regsearch()
Dim LR1, lr2 As Long, i As Long

LR1 = Sheet1.Range("A" & Rows.Count).End(xlUp).Row



Dim data As String

Dim bot As New WebDriver
For i = 2 To 2
Sheet1.Range("A" & i).Copy 'Value is N2

Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")
With clipboard
.GetFromClipboard
data = .getText
End With
'MsgBox data
bot.Start "chrome", "http://avionictools.com"


bot.Wait 2000
bot.get "/icao.php"
bot.Wait 2000


bot.FindElementByName("data").Click

bot.SendKeys data
bot.Wait 2000
bot.FindElementByXPath("//div/input").Click



bot.Wait 1000


Set Table = bot.getElementsByTagName("table").Item(0)
For Each Tr In Table.getElementsByTagName("tr")
tdlen = Tr.getElementsByTagName("td").Length
If tdlen > 1 Then
lr = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1
Sheet1.Range("C" & i).Value = Tr.getElementsByTagName("td").Item(0).innerText
Sheet1.Range("D" & i).Value = Tr.getElementsByTagName("td").Item(1).innerText
Else

End If


Next Tr
Application.Wait Now + TimeValue("00:00:04")


Next
End Sub









share|improve this question
























  • Did you try my answer? I have added another for your revised question.

    – QHarr
    Nov 26 '18 at 19:00













3












3








3


1






I have been trying to import the table results from http://avionictools.com/icao.php
using example Reg code is N2
my code adds the Reg code and clicks the submit button , but I am unable to copy the results from the table. I wanted the hex code copying to column C



Public Sub regsearch()
Dim LR1, lr2 As Long, i As Long

LR1 = Sheet1.Range("A" & Rows.Count).End(xlUp).Row



Dim data As String

Dim bot As New WebDriver
For i = 2 To 2
Sheet1.Range("A" & i).Copy 'Value is N2

Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")
With clipboard
.GetFromClipboard
data = .getText
End With
'MsgBox data
bot.Start "chrome", "http://avionictools.com"


bot.Wait 2000
bot.get "/icao.php"
bot.Wait 2000


bot.FindElementByName("data").Click

bot.SendKeys data
bot.Wait 2000
bot.FindElementByXPath("//div/input").Click



bot.Wait 1000


Set Table = bot.getElementsByTagName("table").Item(0)
For Each Tr In Table.getElementsByTagName("tr")
tdlen = Tr.getElementsByTagName("td").Length
If tdlen > 1 Then
lr = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1
Sheet1.Range("C" & i).Value = Tr.getElementsByTagName("td").Item(0).innerText
Sheet1.Range("D" & i).Value = Tr.getElementsByTagName("td").Item(1).innerText
Else

End If


Next Tr
Application.Wait Now + TimeValue("00:00:04")


Next
End Sub









share|improve this question
















I have been trying to import the table results from http://avionictools.com/icao.php
using example Reg code is N2
my code adds the Reg code and clicks the submit button , but I am unable to copy the results from the table. I wanted the hex code copying to column C



Public Sub regsearch()
Dim LR1, lr2 As Long, i As Long

LR1 = Sheet1.Range("A" & Rows.Count).End(xlUp).Row



Dim data As String

Dim bot As New WebDriver
For i = 2 To 2
Sheet1.Range("A" & i).Copy 'Value is N2

Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")
With clipboard
.GetFromClipboard
data = .getText
End With
'MsgBox data
bot.Start "chrome", "http://avionictools.com"


bot.Wait 2000
bot.get "/icao.php"
bot.Wait 2000


bot.FindElementByName("data").Click

bot.SendKeys data
bot.Wait 2000
bot.FindElementByXPath("//div/input").Click



bot.Wait 1000


Set Table = bot.getElementsByTagName("table").Item(0)
For Each Tr In Table.getElementsByTagName("tr")
tdlen = Tr.getElementsByTagName("td").Length
If tdlen > 1 Then
lr = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1
Sheet1.Range("C" & i).Value = Tr.getElementsByTagName("td").Item(0).innerText
Sheet1.Range("D" & i).Value = Tr.getElementsByTagName("td").Item(1).innerText
Else

End If


Next Tr
Application.Wait Now + TimeValue("00:00:04")


Next
End Sub






excel vba excel-vba selenium






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 18:00







Mr North

















asked Nov 12 '18 at 15:52









Mr NorthMr North

125




125












  • Did you try my answer? I have added another for your revised question.

    – QHarr
    Nov 26 '18 at 19:00

















  • Did you try my answer? I have added another for your revised question.

    – QHarr
    Nov 26 '18 at 19:00
















Did you try my answer? I have added another for your revised question.

– QHarr
Nov 26 '18 at 19:00





Did you try my answer? I have added another for your revised question.

– QHarr
Nov 26 '18 at 19:00












2 Answers
2






active

oldest

votes


















1














The following seems to work for me



Option Explicit

Public Sub GetInfo()
Dim IE As New InternetExplorer, clipboard As Object, ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")

With IE
.Visible = True
.navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp" '"http://www.airlinecodes.co.uk/airlcoderes.asp"

While .Busy Or .readyState < 4: DoEvents: Wend

.document.querySelector("[name=icaocode]").Value = "BAW"
.document.querySelector("[name=submit]").Click

While .Busy Or .readyState < 4: DoEvents: Wend

clipboard.SetText .document.querySelectorAll("table").item(4).outerHTML '.getAttribute("outerHTML")
clipboard.PutInClipboard

.Quit
End With

ws.Cells(1, 1).PasteSpecial

End Sub



Edit:



In answer to your changed question:



Option Explicit
Public Sub test()
Dim bot As New ChromeDriver, ws As Worksheet, text As String, i As Long
Set ws = ThisWorkbook.Worksheets("Sheet1")
With bot
.Start
.get "http://avionictools.com/icao.php"
For i = 1 To 2
.FindElementByCss("input[name=data]").SendKeys "N" & CStr(i)
.FindElementByCss("[type=submit]").submit

text = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).text
ws.Cells(i, 1) = Split(text, Chr$(10))(1)
.FindElementByCss("input[name=data]").Clear
Next
.Quit
End With
End Sub





share|improve this answer

























  • i need to loop when i set a string value for reg and use sendkeys (reg) it does not work

    – Mr North
    Nov 26 '18 at 20:23











  • This code works but I get all the text , i just want to have the hex code value please ws.Range("B" & i).Value = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text

    – Mr North
    Nov 26 '18 at 20:31












  • thanks , last question if it is possible , is there a way to not include Hex: and just have the code

    – Mr North
    Nov 26 '18 at 20:52











  • i have changed the code so the webpage is opened before the loop. but i am unable to clear the value from .FindElementByCss("input[name=data]").SendKeys reg. it is keeping the previous value and adds next value so it N1N2 instead of N2 as N1 is not removed , i tried adding sendkey "" at the end before next but it does not work

    – Mr North
    Nov 26 '18 at 22:05











  • that worked great thanks , is there a way to select an item from the listbox . i want to change it C Number.

    – Mr North
    Nov 26 '18 at 22:18


















0














It's somewhat strange to encounter that error, but you can recover from it by resetting your IE object.



For i = 2 To 2

IE.navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp"
Do
DoEvents
Set IE = GetIE("airlinecodes.co.uk")
Loop While IE.readyState < READYSTATE_COMPLETE
Set DOC = IE.document
DoEvents
DOC.getElementsByName("icaocode").Item(0).Value = Sheet1.Range("A" & i).Value
For Each inpt In DOC.getElementsByTagName("input")
If inpt.Name = "submit" And inpt.Type = "submit" And inpt.Value = "Submit" Then
inpt.Click
Do
DoEvents
Set IE = GetIE("airlinecodes.co.uk")
Loop While IE.readyState < READYSTATE_COMPLETE
Exit For
End If
Next inpt


I've updated two loops here, using



Do
DoEvents
Set IE = GetIE("airlinecodes.co.uk")
Loop While IE.readyState < READYSTATE_COMPLETE


Which means you will at a minimum run this loop once since I moved the While statement to the bottom - what this will do is it will continuously reset your IE object until the page is loaded - again, this is not something you will always encounter when scraping webpages, it's certainly strange though.



You will also need to add the following sub routine to your module as well - this is what's going to reset your IE object:



Function GetIE(sLocation As String) As InternetExplorer

Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim RetVal As InternetExplorer

Set RetVal = Nothing
Set objShell = CreateObject("shell.application")
Set objShellWindows = objShell.Windows

For Each o In objShellWindows
sURL = ""
On Error Resume Next
sURL = o.document.Location
On Error GoTo 0
If sURL Like "*" & sLocation & "*" Then
Set RetVal = o
Exit For
End If
Next o

Set GetIE = RetVal

End Function





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265690%2fselenium-vba-extracting-data-from-web-table-last-bit-of-code-to-copy-text-does-n%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The following seems to work for me



    Option Explicit

    Public Sub GetInfo()
    Dim IE As New InternetExplorer, clipboard As Object, ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")

    With IE
    .Visible = True
    .navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp" '"http://www.airlinecodes.co.uk/airlcoderes.asp"

    While .Busy Or .readyState < 4: DoEvents: Wend

    .document.querySelector("[name=icaocode]").Value = "BAW"
    .document.querySelector("[name=submit]").Click

    While .Busy Or .readyState < 4: DoEvents: Wend

    clipboard.SetText .document.querySelectorAll("table").item(4).outerHTML '.getAttribute("outerHTML")
    clipboard.PutInClipboard

    .Quit
    End With

    ws.Cells(1, 1).PasteSpecial

    End Sub



    Edit:



    In answer to your changed question:



    Option Explicit
    Public Sub test()
    Dim bot As New ChromeDriver, ws As Worksheet, text As String, i As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    With bot
    .Start
    .get "http://avionictools.com/icao.php"
    For i = 1 To 2
    .FindElementByCss("input[name=data]").SendKeys "N" & CStr(i)
    .FindElementByCss("[type=submit]").submit

    text = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).text
    ws.Cells(i, 1) = Split(text, Chr$(10))(1)
    .FindElementByCss("input[name=data]").Clear
    Next
    .Quit
    End With
    End Sub





    share|improve this answer

























    • i need to loop when i set a string value for reg and use sendkeys (reg) it does not work

      – Mr North
      Nov 26 '18 at 20:23











    • This code works but I get all the text , i just want to have the hex code value please ws.Range("B" & i).Value = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text

      – Mr North
      Nov 26 '18 at 20:31












    • thanks , last question if it is possible , is there a way to not include Hex: and just have the code

      – Mr North
      Nov 26 '18 at 20:52











    • i have changed the code so the webpage is opened before the loop. but i am unable to clear the value from .FindElementByCss("input[name=data]").SendKeys reg. it is keeping the previous value and adds next value so it N1N2 instead of N2 as N1 is not removed , i tried adding sendkey "" at the end before next but it does not work

      – Mr North
      Nov 26 '18 at 22:05











    • that worked great thanks , is there a way to select an item from the listbox . i want to change it C Number.

      – Mr North
      Nov 26 '18 at 22:18















    1














    The following seems to work for me



    Option Explicit

    Public Sub GetInfo()
    Dim IE As New InternetExplorer, clipboard As Object, ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")

    With IE
    .Visible = True
    .navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp" '"http://www.airlinecodes.co.uk/airlcoderes.asp"

    While .Busy Or .readyState < 4: DoEvents: Wend

    .document.querySelector("[name=icaocode]").Value = "BAW"
    .document.querySelector("[name=submit]").Click

    While .Busy Or .readyState < 4: DoEvents: Wend

    clipboard.SetText .document.querySelectorAll("table").item(4).outerHTML '.getAttribute("outerHTML")
    clipboard.PutInClipboard

    .Quit
    End With

    ws.Cells(1, 1).PasteSpecial

    End Sub



    Edit:



    In answer to your changed question:



    Option Explicit
    Public Sub test()
    Dim bot As New ChromeDriver, ws As Worksheet, text As String, i As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    With bot
    .Start
    .get "http://avionictools.com/icao.php"
    For i = 1 To 2
    .FindElementByCss("input[name=data]").SendKeys "N" & CStr(i)
    .FindElementByCss("[type=submit]").submit

    text = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).text
    ws.Cells(i, 1) = Split(text, Chr$(10))(1)
    .FindElementByCss("input[name=data]").Clear
    Next
    .Quit
    End With
    End Sub





    share|improve this answer

























    • i need to loop when i set a string value for reg and use sendkeys (reg) it does not work

      – Mr North
      Nov 26 '18 at 20:23











    • This code works but I get all the text , i just want to have the hex code value please ws.Range("B" & i).Value = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text

      – Mr North
      Nov 26 '18 at 20:31












    • thanks , last question if it is possible , is there a way to not include Hex: and just have the code

      – Mr North
      Nov 26 '18 at 20:52











    • i have changed the code so the webpage is opened before the loop. but i am unable to clear the value from .FindElementByCss("input[name=data]").SendKeys reg. it is keeping the previous value and adds next value so it N1N2 instead of N2 as N1 is not removed , i tried adding sendkey "" at the end before next but it does not work

      – Mr North
      Nov 26 '18 at 22:05











    • that worked great thanks , is there a way to select an item from the listbox . i want to change it C Number.

      – Mr North
      Nov 26 '18 at 22:18













    1












    1








    1







    The following seems to work for me



    Option Explicit

    Public Sub GetInfo()
    Dim IE As New InternetExplorer, clipboard As Object, ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")

    With IE
    .Visible = True
    .navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp" '"http://www.airlinecodes.co.uk/airlcoderes.asp"

    While .Busy Or .readyState < 4: DoEvents: Wend

    .document.querySelector("[name=icaocode]").Value = "BAW"
    .document.querySelector("[name=submit]").Click

    While .Busy Or .readyState < 4: DoEvents: Wend

    clipboard.SetText .document.querySelectorAll("table").item(4).outerHTML '.getAttribute("outerHTML")
    clipboard.PutInClipboard

    .Quit
    End With

    ws.Cells(1, 1).PasteSpecial

    End Sub



    Edit:



    In answer to your changed question:



    Option Explicit
    Public Sub test()
    Dim bot As New ChromeDriver, ws As Worksheet, text As String, i As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    With bot
    .Start
    .get "http://avionictools.com/icao.php"
    For i = 1 To 2
    .FindElementByCss("input[name=data]").SendKeys "N" & CStr(i)
    .FindElementByCss("[type=submit]").submit

    text = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).text
    ws.Cells(i, 1) = Split(text, Chr$(10))(1)
    .FindElementByCss("input[name=data]").Clear
    Next
    .Quit
    End With
    End Sub





    share|improve this answer















    The following seems to work for me



    Option Explicit

    Public Sub GetInfo()
    Dim IE As New InternetExplorer, clipboard As Object, ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set clipboard = GetObject("New:1C3B4210-F441-11CE-B9EA-00AA006B1A69")

    With IE
    .Visible = True
    .navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp" '"http://www.airlinecodes.co.uk/airlcoderes.asp"

    While .Busy Or .readyState < 4: DoEvents: Wend

    .document.querySelector("[name=icaocode]").Value = "BAW"
    .document.querySelector("[name=submit]").Click

    While .Busy Or .readyState < 4: DoEvents: Wend

    clipboard.SetText .document.querySelectorAll("table").item(4).outerHTML '.getAttribute("outerHTML")
    clipboard.PutInClipboard

    .Quit
    End With

    ws.Cells(1, 1).PasteSpecial

    End Sub



    Edit:



    In answer to your changed question:



    Option Explicit
    Public Sub test()
    Dim bot As New ChromeDriver, ws As Worksheet, text As String, i As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    With bot
    .Start
    .get "http://avionictools.com/icao.php"
    For i = 1 To 2
    .FindElementByCss("input[name=data]").SendKeys "N" & CStr(i)
    .FindElementByCss("[type=submit]").submit

    text = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).text
    ws.Cells(i, 1) = Split(text, Chr$(10))(1)
    .FindElementByCss("input[name=data]").Clear
    Next
    .Quit
    End With
    End Sub






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 26 '18 at 22:09

























    answered Nov 12 '18 at 17:36









    QHarrQHarr

    31.3k81941




    31.3k81941












    • i need to loop when i set a string value for reg and use sendkeys (reg) it does not work

      – Mr North
      Nov 26 '18 at 20:23











    • This code works but I get all the text , i just want to have the hex code value please ws.Range("B" & i).Value = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text

      – Mr North
      Nov 26 '18 at 20:31












    • thanks , last question if it is possible , is there a way to not include Hex: and just have the code

      – Mr North
      Nov 26 '18 at 20:52











    • i have changed the code so the webpage is opened before the loop. but i am unable to clear the value from .FindElementByCss("input[name=data]").SendKeys reg. it is keeping the previous value and adds next value so it N1N2 instead of N2 as N1 is not removed , i tried adding sendkey "" at the end before next but it does not work

      – Mr North
      Nov 26 '18 at 22:05











    • that worked great thanks , is there a way to select an item from the listbox . i want to change it C Number.

      – Mr North
      Nov 26 '18 at 22:18

















    • i need to loop when i set a string value for reg and use sendkeys (reg) it does not work

      – Mr North
      Nov 26 '18 at 20:23











    • This code works but I get all the text , i just want to have the hex code value please ws.Range("B" & i).Value = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text

      – Mr North
      Nov 26 '18 at 20:31












    • thanks , last question if it is possible , is there a way to not include Hex: and just have the code

      – Mr North
      Nov 26 '18 at 20:52











    • i have changed the code so the webpage is opened before the loop. but i am unable to clear the value from .FindElementByCss("input[name=data]").SendKeys reg. it is keeping the previous value and adds next value so it N1N2 instead of N2 as N1 is not removed , i tried adding sendkey "" at the end before next but it does not work

      – Mr North
      Nov 26 '18 at 22:05











    • that worked great thanks , is there a way to select an item from the listbox . i want to change it C Number.

      – Mr North
      Nov 26 '18 at 22:18
















    i need to loop when i set a string value for reg and use sendkeys (reg) it does not work

    – Mr North
    Nov 26 '18 at 20:23





    i need to loop when i set a string value for reg and use sendkeys (reg) it does not work

    – Mr North
    Nov 26 '18 at 20:23













    This code works but I get all the text , i just want to have the hex code value please ws.Range("B" & i).Value = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text

    – Mr North
    Nov 26 '18 at 20:31






    This code works but I get all the text , i just want to have the hex code value please ws.Range("B" & i).Value = .FindElementsByTag("table")(1).FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text

    – Mr North
    Nov 26 '18 at 20:31














    thanks , last question if it is possible , is there a way to not include Hex: and just have the code

    – Mr North
    Nov 26 '18 at 20:52





    thanks , last question if it is possible , is there a way to not include Hex: and just have the code

    – Mr North
    Nov 26 '18 at 20:52













    i have changed the code so the webpage is opened before the loop. but i am unable to clear the value from .FindElementByCss("input[name=data]").SendKeys reg. it is keeping the previous value and adds next value so it N1N2 instead of N2 as N1 is not removed , i tried adding sendkey "" at the end before next but it does not work

    – Mr North
    Nov 26 '18 at 22:05





    i have changed the code so the webpage is opened before the loop. but i am unable to clear the value from .FindElementByCss("input[name=data]").SendKeys reg. it is keeping the previous value and adds next value so it N1N2 instead of N2 as N1 is not removed , i tried adding sendkey "" at the end before next but it does not work

    – Mr North
    Nov 26 '18 at 22:05













    that worked great thanks , is there a way to select an item from the listbox . i want to change it C Number.

    – Mr North
    Nov 26 '18 at 22:18





    that worked great thanks , is there a way to select an item from the listbox . i want to change it C Number.

    – Mr North
    Nov 26 '18 at 22:18













    0














    It's somewhat strange to encounter that error, but you can recover from it by resetting your IE object.



    For i = 2 To 2

    IE.navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp"
    Do
    DoEvents
    Set IE = GetIE("airlinecodes.co.uk")
    Loop While IE.readyState < READYSTATE_COMPLETE
    Set DOC = IE.document
    DoEvents
    DOC.getElementsByName("icaocode").Item(0).Value = Sheet1.Range("A" & i).Value
    For Each inpt In DOC.getElementsByTagName("input")
    If inpt.Name = "submit" And inpt.Type = "submit" And inpt.Value = "Submit" Then
    inpt.Click
    Do
    DoEvents
    Set IE = GetIE("airlinecodes.co.uk")
    Loop While IE.readyState < READYSTATE_COMPLETE
    Exit For
    End If
    Next inpt


    I've updated two loops here, using



    Do
    DoEvents
    Set IE = GetIE("airlinecodes.co.uk")
    Loop While IE.readyState < READYSTATE_COMPLETE


    Which means you will at a minimum run this loop once since I moved the While statement to the bottom - what this will do is it will continuously reset your IE object until the page is loaded - again, this is not something you will always encounter when scraping webpages, it's certainly strange though.



    You will also need to add the following sub routine to your module as well - this is what's going to reset your IE object:



    Function GetIE(sLocation As String) As InternetExplorer

    Dim objShell As Object, objShellWindows As Object, o As Object
    Dim sURL As String
    Dim RetVal As InternetExplorer

    Set RetVal = Nothing
    Set objShell = CreateObject("shell.application")
    Set objShellWindows = objShell.Windows

    For Each o In objShellWindows
    sURL = ""
    On Error Resume Next
    sURL = o.document.Location
    On Error GoTo 0
    If sURL Like "*" & sLocation & "*" Then
    Set RetVal = o
    Exit For
    End If
    Next o

    Set GetIE = RetVal

    End Function





    share|improve this answer



























      0














      It's somewhat strange to encounter that error, but you can recover from it by resetting your IE object.



      For i = 2 To 2

      IE.navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp"
      Do
      DoEvents
      Set IE = GetIE("airlinecodes.co.uk")
      Loop While IE.readyState < READYSTATE_COMPLETE
      Set DOC = IE.document
      DoEvents
      DOC.getElementsByName("icaocode").Item(0).Value = Sheet1.Range("A" & i).Value
      For Each inpt In DOC.getElementsByTagName("input")
      If inpt.Name = "submit" And inpt.Type = "submit" And inpt.Value = "Submit" Then
      inpt.Click
      Do
      DoEvents
      Set IE = GetIE("airlinecodes.co.uk")
      Loop While IE.readyState < READYSTATE_COMPLETE
      Exit For
      End If
      Next inpt


      I've updated two loops here, using



      Do
      DoEvents
      Set IE = GetIE("airlinecodes.co.uk")
      Loop While IE.readyState < READYSTATE_COMPLETE


      Which means you will at a minimum run this loop once since I moved the While statement to the bottom - what this will do is it will continuously reset your IE object until the page is loaded - again, this is not something you will always encounter when scraping webpages, it's certainly strange though.



      You will also need to add the following sub routine to your module as well - this is what's going to reset your IE object:



      Function GetIE(sLocation As String) As InternetExplorer

      Dim objShell As Object, objShellWindows As Object, o As Object
      Dim sURL As String
      Dim RetVal As InternetExplorer

      Set RetVal = Nothing
      Set objShell = CreateObject("shell.application")
      Set objShellWindows = objShell.Windows

      For Each o In objShellWindows
      sURL = ""
      On Error Resume Next
      sURL = o.document.Location
      On Error GoTo 0
      If sURL Like "*" & sLocation & "*" Then
      Set RetVal = o
      Exit For
      End If
      Next o

      Set GetIE = RetVal

      End Function





      share|improve this answer

























        0












        0








        0







        It's somewhat strange to encounter that error, but you can recover from it by resetting your IE object.



        For i = 2 To 2

        IE.navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp"
        Do
        DoEvents
        Set IE = GetIE("airlinecodes.co.uk")
        Loop While IE.readyState < READYSTATE_COMPLETE
        Set DOC = IE.document
        DoEvents
        DOC.getElementsByName("icaocode").Item(0).Value = Sheet1.Range("A" & i).Value
        For Each inpt In DOC.getElementsByTagName("input")
        If inpt.Name = "submit" And inpt.Type = "submit" And inpt.Value = "Submit" Then
        inpt.Click
        Do
        DoEvents
        Set IE = GetIE("airlinecodes.co.uk")
        Loop While IE.readyState < READYSTATE_COMPLETE
        Exit For
        End If
        Next inpt


        I've updated two loops here, using



        Do
        DoEvents
        Set IE = GetIE("airlinecodes.co.uk")
        Loop While IE.readyState < READYSTATE_COMPLETE


        Which means you will at a minimum run this loop once since I moved the While statement to the bottom - what this will do is it will continuously reset your IE object until the page is loaded - again, this is not something you will always encounter when scraping webpages, it's certainly strange though.



        You will also need to add the following sub routine to your module as well - this is what's going to reset your IE object:



        Function GetIE(sLocation As String) As InternetExplorer

        Dim objShell As Object, objShellWindows As Object, o As Object
        Dim sURL As String
        Dim RetVal As InternetExplorer

        Set RetVal = Nothing
        Set objShell = CreateObject("shell.application")
        Set objShellWindows = objShell.Windows

        For Each o In objShellWindows
        sURL = ""
        On Error Resume Next
        sURL = o.document.Location
        On Error GoTo 0
        If sURL Like "*" & sLocation & "*" Then
        Set RetVal = o
        Exit For
        End If
        Next o

        Set GetIE = RetVal

        End Function





        share|improve this answer













        It's somewhat strange to encounter that error, but you can recover from it by resetting your IE object.



        For i = 2 To 2

        IE.navigate "http://www.airlinecodes.co.uk/airlcodesearch.asp"
        Do
        DoEvents
        Set IE = GetIE("airlinecodes.co.uk")
        Loop While IE.readyState < READYSTATE_COMPLETE
        Set DOC = IE.document
        DoEvents
        DOC.getElementsByName("icaocode").Item(0).Value = Sheet1.Range("A" & i).Value
        For Each inpt In DOC.getElementsByTagName("input")
        If inpt.Name = "submit" And inpt.Type = "submit" And inpt.Value = "Submit" Then
        inpt.Click
        Do
        DoEvents
        Set IE = GetIE("airlinecodes.co.uk")
        Loop While IE.readyState < READYSTATE_COMPLETE
        Exit For
        End If
        Next inpt


        I've updated two loops here, using



        Do
        DoEvents
        Set IE = GetIE("airlinecodes.co.uk")
        Loop While IE.readyState < READYSTATE_COMPLETE


        Which means you will at a minimum run this loop once since I moved the While statement to the bottom - what this will do is it will continuously reset your IE object until the page is loaded - again, this is not something you will always encounter when scraping webpages, it's certainly strange though.



        You will also need to add the following sub routine to your module as well - this is what's going to reset your IE object:



        Function GetIE(sLocation As String) As InternetExplorer

        Dim objShell As Object, objShellWindows As Object, o As Object
        Dim sURL As String
        Dim RetVal As InternetExplorer

        Set RetVal = Nothing
        Set objShell = CreateObject("shell.application")
        Set objShellWindows = objShell.Windows

        For Each o In objShellWindows
        sURL = ""
        On Error Resume Next
        sURL = o.document.Location
        On Error GoTo 0
        If sURL Like "*" & sLocation & "*" Then
        Set RetVal = o
        Exit For
        End If
        Next o

        Set GetIE = RetVal

        End Function






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 16:55









        K.DᴀᴠɪsK.Dᴀᴠɪs

        7,114112339




        7,114112339



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265690%2fselenium-vba-extracting-data-from-web-table-last-bit-of-code-to-copy-text-does-n%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo