I created an Excel list of image locations to be sent to Web Whatsapp in Chrome. I am using Selenium with VBA. The first image is sent correctly with its caption, however, from the second item in the list and on, the Sendkeys ArrowDown does not work. For some reason, the focus goes to the address bar in Chrome and I am not being able to make it happen.
Here is the code I use:
<code>wsi is defined as WorkSheet
BOT is the Webdriver
1199 Set FSO = CreateObject("Scripting.FileSystemObject")
1200 With wsi
1210 For i = fline To lline
1220 PicLocation = .Cells(i, 1).Value
1230 ImageCaption = .Cells(i, 2).Value
1215 If PicLocation <> "" Then
' Before trying to send anything, check if file exists
1250 If FSO.FileExists(PicLocation) = False Then
GoTo NextIteration
1260 End If
1265 'BOT.FindElementByXPath(xPathSearchInputField).WaitDisplayed(True).Click
1270 BOT.FindElement(By.XPath(AttachmentButton)).WaitDisplayed(True).Click
1290 BOT.Wait (1200)
1300 BOT.SendKeys ks.ArrowDown
1310 BOT.Wait (1200)
1320 BOT.SendKeys ks.ArrowDown
1330 BOT.Wait (1200)
1340 BOT.SendKeys ks.Return
1350 BOT.Wait (1700)
1360 Application.SendKeys (PicLocation)
1370 BOT.Wait (1500)
1380 Application.SendKeys ("{Enter}")
1390 BOT.Wait (1500)
1395 'BOT.FindElementByXPath (xPathCaption)
1400 BOT.SendKeys (ImageCaption)
1410 BOT.Wait (DefaultDelay)
1420 BOT.SendKeys (ks.Enter)
1435 End If
NextIteration:
1440 Next i
1450 End With
</code>
<code>wsi is defined as WorkSheet
BOT is the Webdriver
1199 Set FSO = CreateObject("Scripting.FileSystemObject")
1200 With wsi
1210 For i = fline To lline
1220 PicLocation = .Cells(i, 1).Value
1230 ImageCaption = .Cells(i, 2).Value
1215 If PicLocation <> "" Then
' Before trying to send anything, check if file exists
1250 If FSO.FileExists(PicLocation) = False Then
GoTo NextIteration
1260 End If
1265 'BOT.FindElementByXPath(xPathSearchInputField).WaitDisplayed(True).Click
1270 BOT.FindElement(By.XPath(AttachmentButton)).WaitDisplayed(True).Click
1290 BOT.Wait (1200)
1300 BOT.SendKeys ks.ArrowDown
1310 BOT.Wait (1200)
1320 BOT.SendKeys ks.ArrowDown
1330 BOT.Wait (1200)
1340 BOT.SendKeys ks.Return
1350 BOT.Wait (1700)
1360 Application.SendKeys (PicLocation)
1370 BOT.Wait (1500)
1380 Application.SendKeys ("{Enter}")
1390 BOT.Wait (1500)
1395 'BOT.FindElementByXPath (xPathCaption)
1400 BOT.SendKeys (ImageCaption)
1410 BOT.Wait (DefaultDelay)
1420 BOT.SendKeys (ks.Enter)
1435 End If
NextIteration:
1440 Next i
1450 End With
</code>
wsi is defined as WorkSheet
BOT is the Webdriver
1199 Set FSO = CreateObject("Scripting.FileSystemObject")
1200 With wsi
1210 For i = fline To lline
1220 PicLocation = .Cells(i, 1).Value
1230 ImageCaption = .Cells(i, 2).Value
1215 If PicLocation <> "" Then
' Before trying to send anything, check if file exists
1250 If FSO.FileExists(PicLocation) = False Then
GoTo NextIteration
1260 End If
1265 'BOT.FindElementByXPath(xPathSearchInputField).WaitDisplayed(True).Click
1270 BOT.FindElement(By.XPath(AttachmentButton)).WaitDisplayed(True).Click
1290 BOT.Wait (1200)
1300 BOT.SendKeys ks.ArrowDown
1310 BOT.Wait (1200)
1320 BOT.SendKeys ks.ArrowDown
1330 BOT.Wait (1200)
1340 BOT.SendKeys ks.Return
1350 BOT.Wait (1700)
1360 Application.SendKeys (PicLocation)
1370 BOT.Wait (1500)
1380 Application.SendKeys ("{Enter}")
1390 BOT.Wait (1500)
1395 'BOT.FindElementByXPath (xPathCaption)
1400 BOT.SendKeys (ImageCaption)
1410 BOT.Wait (DefaultDelay)
1420 BOT.SendKeys (ks.Enter)
1435 End If
NextIteration:
1440 Next i
1450 End With
New contributor
Nabil Tarabichi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.