BalloutMoe
Board Regular
- Joined
- Jun 4, 2021
- Messages
- 137
- Office Version
- 365
- Platform
- Windows
Hello below is a code I use however sometimes I encounter problems with certain lines that I need them to repeat that step then continue. Looking for some help here, thank you
I added a bunch of driver.wait lines just to help, for the most part the code works but occasionally the site takes a while to load and it throws errors or the internet is slow. Please if you can help me out I would greatly appreciate it. Thank you
VBA Code:
Sub GetDatafromEdge()
Dim findby As New Selenium.By
Dim driver As New WebDriver
'Set driver = New WebDriver
Dim keys As New Selenium.keys
driver.Start "edge", ""
'Website I access here
driver.FindElementByName("ctl00$cpMain$logMain$UserName").SendKeys "****"
driver.FindElementByName("ctl00$cpMain$logMain$Password").SendKeys "*****"
driver.FindElementByName("ctl00$cpMain$logMain$LoginButton").Click
Dim LastRow As Long
LastRow = Range("F" & Rows.Count).End(xlUp).Row
Dim filename As String
With driver
'Open Edge and navigate to website
For Each Url In ActiveWorkbook.ActiveSheet.Range("F2:F" & LastRow)
.Get Url.Value
filename = Url.Offset(0, -5).Value & " " & Url.Offset(0, -1).Value
driver.Wait 3000
[COLOR=rgb(97, 189, 109)]'I am having issues here sometimes it does not find the element and it kicks me out with the error, I would like to add an error handling in case it does not to repeat this step until it finds it.[/COLOR]
driver.FindElementById("VisibleReportContentrptMain_ctl13").FindElementByTag("div").WaitDisplayed
driver.Wait 3000
[COLOR=rgb(97, 189, 109)]'Also same issue here[/COLOR]
driver.FindElementByCss(".ToolbarExport.WidgetSet").Click
driver.Wait 1000
'Application.Wait Now + TimeValue("00:00:2")
[COLOR=rgb(97, 189, 109)]'Also same issue here[/COLOR]
driver.FindElementByXPath("//a[@title='PDF']").Click
driver.Wait 2000
'Application.Wait Now + TimeValue("00:00:1")
[COLOR=rgb(97, 189, 109)]'Also same issue here[/COLOR]
Name "C:\Users\Downloads\rptNG2COSInvoice.pdf" As "C:\Users\Downloads\" & filename & ".pdf"
Next
End With
driver.Wait 2000
End Sub
I added a bunch of driver.wait lines just to help, for the most part the code works but occasionally the site takes a while to load and it throws errors or the internet is slow. Please if you can help me out I would greatly appreciate it. Thank you