0

Will go to the school page and click on the like button. I'm going to the page object htmldivelement feature does not click the button. My commands are running with IE10, but it doesn't work with IE11.

Set hIE = CreateObject("InternetExplorer.Application")   
hURL = "http://mukerremalikayanilkokulu.meb.k12.tr/icerikler/eglen-dusun-bul_6506730.html"

With hIE
    .Navigate hURL
    .Visible = True

    Do While hIE.Busy
    Loop
End With

Set haberss = hIE.document.getElementsByClassName("begen")
For Each haberbb In haberss
    If haberbb = "begen" Then
        Do While hIE.Busy
        Loop
        haberbb.Click
        Set hIE = hIE.Quit
        Exit For
    Else
        Do While hIE.Busy
        Loop
        haberbb.Click
        Set hIE = hIE.Quit
        Exit For
    End If

The haberbb button works on IE10, but on IE11 it does not work.

QHarr
  • 83,427
  • 12
  • 54
  • 101
  • 1
    Note that your `If` statement `If haberbb = "begen" Then` doesn't make any sense. It runs exactly the same code on `Then` as on `Else`! – Pᴇʜ Feb 13 '19 at 14:49
  • Thank you for your answer. I'm aware of my mistake. But I did it this way to see if they clicked positively or negatively. – Zeyyat İZGİ Feb 13 '19 at 18:28

2 Answers2

1

I don’t know if that is functional or needs some form of login. I cannot manually click like.

Here are 3 code ways:

Ie.document.querySelector(".begen").click

Ie.document.querySelector(".begen").FireEvent "OnClick"

Ie.document.parentWindow.execScript "document.querySelector('.begen').click;"

Option Explicit
Public Sub AttemptClick()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True
        .Navigate2 "http://mukerremalikayanilkokulu.meb.k12.tr/icerikler/eglen-dusun-bul_6506730.html"
        While .Busy Or .readyState < 4: DoEvents: Wend
        .document.querySelector(".begen").FireEvent "onclick"
        .document.querySelector(".begen").Click
        .document.parentWindow.execScript "document.querySelector('.begen').click();"
        Stop
        .Quit
    End With
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • 1
    Thanks for that @Pᴇʜ – QHarr Feb 13 '19 at 16:31
  • Thank you for your answer. I will try and inform you at the first opportunity – Zeyyat İZGİ Feb 13 '19 at 18:17
  • I try to click the like button and I can click it manually, than I try to run the @QHarr code and find that it is also working on my side with IE 11. Here is the testing result. https://i.postimg.cc/gJyYJMcS/45.gif – Deepak-MSFT Feb 14 '19 at 02:11
  • Thank you. "querySelector" has solved my problem. Thanks for learning something new. Thanks again. – Zeyyat İZGİ Feb 14 '19 at 07:47
  • Dear Qharr , When I clicked the button, they did it with a "like" increase. What I want to do is increase by 10 when I click. Is there a way to do this? – Zeyyat İZGİ Feb 14 '19 at 14:27
  • if you want to do 10 clicks then put the .click line instead of a for loop which runs from 1 to 10. – QHarr Feb 15 '19 at 08:05
  • When I press the like button, the number is increasing. but when I press a second time, the number doesn't increase. I think there is a case about the script. if I can solve it for - next cycle solves my job as you said. – Zeyyat İZGİ Feb 15 '19 at 15:12
  • Can you manually increase it more than once? I suspect the page is designed to prevent someone sock-puppet like voting. – QHarr Feb 15 '19 at 15:13
0

In addition to QHarr's answer, your Do While...Loop isn't quite right.

  1. You should do something in the loop, otherwise you are just going to spike the CPU usage. You should at least add a DoEvents in between to allow windows to process other programs/messages.
  2. It doesn't look like you are waiting for the page load to complete. Try adding Or ReadyState < READYSTATE_COMPLETE to the loop condition.

Putting it together, the loop should look like:

Do While IE.Busy Or IE.ReadyState < READYSTATE_COMPLETE ' = 4
    DoEvents
Loop

Here are some other references that might help:

Failproof Wait for IE to load

How to wait for the page to load after click

Profex
  • 1,370
  • 8
  • 20