1

I searched all over the internet and in this forum and can't find the answer. Below code is used to upload file to a wordpress website. When I use F8 to step through it, it works fine. However, when run the full code, after the upload using XPath ("//input[starts-with(id, 'htm15_')]").SendKeys (ws.Cells(1.4)), the macro seems to skip the next line which is to click on a button (Insert file URL) and the browser stucks on this uploading page and will not load the next page where the Publish button appears. At this point, an error came out and stated couldn't find the element Publish.

I try different things, adding global ImplicitWait, adding timeouts for the above mentioned lines of code and to no avail. It seems that after uploading the file, the macro just doesn't click the button (skips that line of code) and therefore couldn't find the Publish button in the next line. The problem lines of code have been indicated by 2 asterisks. Appreciate any help.

The Error Message

Public Sub UploadPost()

 Dim ws As Worksheet
 Dim filename As String
 Dim wb As Workbook
 Dim D As WebDriver
 Dim Path As String
 Dim i As Integer

    Set ws = ThisWorkbook.Worksheets("Data")
    Set D = New ChromeDriver
    Const URL = "https://www.myweb.com/login/"

'To login to website

    With D
        .Timeouts.ImplicitWait = 10000    'global implicit wait 5 seconds than default 3 seconds
        .Start "Chrome"
        .Window.Maximize
        .Get URL
        .FindElementById("user_login").SendKeys("id").Click
        .FindElementById("user_pass").SendKeys("pw").Click
        .FindElementByName("submit").Click

    End With

'Upload daily file to Download Monitor and get file ID

        ws.Range("H2:H9").Clear
        D.FindElementById("menu-posts-dlm_download").Click          'Click Download on left menu

  For i = 2 To 9

    With D

        .FindElementByClass("page-title-action").Click                                          'Click Add New
        .FindElementById("title").SendKeys(ws.Cells(i, 2)).Click                                'Type title copy from spreadsheet
        .FindElementById("_members_only").Click                                                 'Click members only category
        .FindElementById(ws.Cells(i, 3)).Click                                                  '17-china, 21-HK, 25-NAS, 10-NYSE
        .FindElementByLinkText("Add file").Click                                                'Add File
        .FindElementByXPath("//input[starts-with(@id,'dp')]").Clear                             'Select the correct date
        .FindElementByXPath("//input[starts-with(@id,'dp')]").SendKeys (ws.Cells(i, 9))
        .FindElementByLinkText("Upload file").Click
        .FindElementByLinkText("Upload Files").Click
        .FindElementByXPath("//input[starts-with(@id,'html5_')]").SendKeys (ws.Cells(i, 4))      'upload file using path from spreadsheet
        **.FindElementByXPath("//*[@id='__wp-uploader-id-0']/div[5]/div/div[2]/button").Click      'Click save Insert file URL
        .FindElementById("publish").Click**
        ws.Cells(i, 8) = D.FindElementByXPath("//*[@id='dlm-info-url']").Value


    End With

   Next i
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
sKhan
  • 29
  • 1
  • 4
  • I have reviewed the posts you have linked here and tried to adjust my code but couldn't resolve it. It is because I can't find the same commands in those posts such as .wait.until elementobeclickable etc. as I'm using selenium basic type library in VBA. Any help in putting together the right command for selenium basic vba is greatly appreciated. – sKhan Nov 14 '18 at 19:19
  • My code is working now. I inserted a .wait (5000) after the upload code and before clicking the button code and now it's running good. Thanks! – sKhan Nov 14 '18 at 21:23

0 Answers0