Selenium + VBA - Ler item em ListBox e Campos de Datas
Enviado: Qua Jul 22, 2020 4:52 pm
Pessoal, estou quebrando a cabeça e não encontrei essa explicação em lugar algum. Estou montando um código VBA com Selenium pra ler do site da B3 e buscar cotações, só que lá tem um componente de ListBox com algumas opções e um Seletor de Datas. Tentei de tudo pra ler e preencher através dos comandos do Selenium e não dá certo, não encontro o objeto. Segue meu código abaixo e erro apresentado pelo VBA, alguém já fez esse tipo de consulta e poderia ajudar?
Erro em tempo de execução '7':
NosuchElementError
Element not found for
XPath=//*[@id=""divContainerIframeBmf""]/form/div/div/div[1]/div[1]/di
Código VBA Utilizado:
Sub ConsultaB3Cot()
Set Driver = New ChromeDriver
Driver.Get "http://www.b3.com.br/pt_br/market-data- ... -fbovespa/"
Application.Wait Now + TimeValue("00:00:03")
Dim Indexador As String: Indexador = "Real x dólar"
Dim DataSelect As Date: DataSelect = "19/07/2020"
Dim Indice As WebElement, Data As WebElement, dropdown As WebElement
Driver.FindElementByXPath("//*[@id=""divContainerIframeBmf""]/form/div/div/div[1]/div[1]/div/div/select").Click
Driver.FindElementByXPath("//*[@id=""divContainerIframeBmf""]/form/div/div/div[1]/div[1]/div/div/select").SendKeys Indexador
Driver.FindElementByXPath("//*[@id=""Data""]").Click
Driver.FindElementByXPath("//*[@id=""Data""]").SendKeys DataSelect
Driver.FindElementByXPath("//*[@id=""Data""]").Click
If Not Ibovespa Is Nothing Then
Sheets("Cotações").Range("Ibovespa1").Value = Ibovespa.Text
Driver.Quit
MsgBox "Ibovespa atualizado"
Else
Driver.Quit
MsgBox "Ibovespa não encontrado"
End If
End Sub
Erro em tempo de execução '7':
NosuchElementError
Element not found for
XPath=//*[@id=""divContainerIframeBmf""]/form/div/div/div[1]/div[1]/di
Código VBA Utilizado:
Sub ConsultaB3Cot()
Set Driver = New ChromeDriver
Driver.Get "http://www.b3.com.br/pt_br/market-data- ... -fbovespa/"
Application.Wait Now + TimeValue("00:00:03")
Dim Indexador As String: Indexador = "Real x dólar"
Dim DataSelect As Date: DataSelect = "19/07/2020"
Dim Indice As WebElement, Data As WebElement, dropdown As WebElement
Driver.FindElementByXPath("//*[@id=""divContainerIframeBmf""]/form/div/div/div[1]/div[1]/div/div/select").Click
Driver.FindElementByXPath("//*[@id=""divContainerIframeBmf""]/form/div/div/div[1]/div[1]/div/div/select").SendKeys Indexador
Driver.FindElementByXPath("//*[@id=""Data""]").Click
Driver.FindElementByXPath("//*[@id=""Data""]").SendKeys DataSelect
Driver.FindElementByXPath("//*[@id=""Data""]").Click
If Not Ibovespa Is Nothing Then
Sheets("Cotações").Range("Ibovespa1").Value = Ibovespa.Text
Driver.Quit
MsgBox "Ibovespa atualizado"
Else
Driver.Quit
MsgBox "Ibovespa não encontrado"
End If
End Sub