Execute javascript:void(0) click using Selenium and VBA

309 views
Skip to first unread message

John Novak

unread,
Oct 2, 2018, 2:34:25 AM10/2/18
to Selenium Users
Hi,


This website uses javascript:void() to click on a link to display more comments.

I have used in the past something like this (VBA) but it seems that it does not work when the javascript link is not visible:


Do
   
Set bt_next = drv.FindElementByLinkText("+ Zobacz poprzednie komentarze", timeout:=3000, Raise:=False)
   
Application.Wait Now + #12:00:01 AM#
   
   
If bt_next Is Nothing Then Exit Do
    bt_next
.Click
Loop




Here is the code from the page that I am trying to "click":

<a class="view-prev" href="javascript:void(0)" data-api-url="/comments-api/comments?sourceId=Post-899171&amp;sort=NEWEST&last=1538404862282&limit=15">+ Zobacz poprzednie komentarze</a>


What would I need to change in the
bt_next.click

command to be able to "click" the link?

Thanks,
John

David

unread,
Oct 2, 2018, 8:39:20 PM10/2/18
to Selenium Users
Consider using VBA's version of WebDriver JavascriptExecutor if that's available, then with that execute the javascript code that performs a mouse click against a DOM element, that method usually works, not sure about if the element is hidden, then you may need to make it visible by changing its property via javascript 1st.
Reply all
Reply to author
Forward
0 new messages