phantomjs icon indicating copy to clipboard operation
phantomjs copied to clipboard

Clicking on a Hyperlink in PhantomJS

Open jobinsjohn opened this issue 12 years ago • 9 comments

Hi,

I am trying to automate login on a website and i m able to fill the username and password in the field. But when i try to click on "sign in" nothing is happening. Later when i inspected the element i found that its a hyperlink.

Can you please suggest me a way to trigger an event to that hyperlink,

jobinsjohn avatar Aug 06 '14 11:08 jobinsjohn

@jobinsjohn Hi, your problem sloved?

wcccode avatar Aug 11 '14 06:08 wcccode

@wcccode Yeah i solved the problem and found a way to solve it. But now i am facing another situation which i am not able to tackle. How to click on any element without any id or class name?

jobinsjohn avatar Aug 11 '14 13:08 jobinsjohn

@jobinsjohn How did you sloved?

wcccode avatar Aug 12 '14 02:08 wcccode

yeah, i want to know "How to click on any element without any id or class name" too ?

andypeker avatar Aug 12 '14 05:08 andypeker

if where are some elements in li/ul, and these elements have no id or class, so how to click them ?

andypeker avatar Aug 12 '14 05:08 andypeker

and another problem, some elements where attributes like 'data="xxx"' and 'data-info="zzz"', other attributes are all same, so how to click one (could i give ${date} or ${data-info} ?)

andypeker avatar Aug 12 '14 05:08 andypeker

@wcccode The sample code for my solutions is as follows

page.evaluate(function()
                {
                          var a = document.getElementById("ID_OF_YOUR_CONTROL"); // you can also use getElementByClassName
                          var e = document.createEvent('MouseEvents');
                          e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                          a.dispatchEvent(e);
                          waitforload = true; // this is for some delay so that the page loads properly.
                });

This is how i solved the problem

jobinsjohn avatar Aug 12 '14 05:08 jobinsjohn

@andypeker I am doing my research on that. Will let you know as soon as i get a solution for it. You can also report the problem in the main section also.

jobinsjohn avatar Aug 12 '14 05:08 jobinsjohn

Please post support question to the mailing-list.

ariya avatar Aug 20 '14 14:08 ariya