Browse a menudriven link via Selenium Web Driver in Perl

42 views
Skip to first unread message

Aditya Khaund

unread,
Feb 9, 2018, 12:06:22 PM2/9/18
to Selenium Remote Driver
I have a following scenario where in I need to navigate to a menu driven link via Selenium for one of my test Case . A Sample menu in the Browser goes like this

Administration->College->Manage.  I need help or some sample code to navigate such a path via selenium driver using perl

George Baugh

unread,
Feb 10, 2018, 9:45:24 AM2/10/18
to Selenium Remote Driver
Is it one of those kind of menus that disappears when you aren't hovering over one of the menu items?  Hate those things.  If not, repeated find_element() calls should do the trick.

Example (supposing you have a Selenium::Remote::Driver object already called $driver):

$driver->find_element('menu_summoner','id')->click();
$driver->find_element('menu_level_one_button','id')->click();
...
$driver->find_element('menu_level_n_button,'id')->click();

Now if you have to keep hovered, that can be quite difficult, as some driver backends would move the cursor back to center after every action.
This was what actionChains were made to fix, but those are only really available and useful on firefox and the newest geckodriver, so I wouldn't bet the farm on them.

If the element is present in the DOM but just hidden, you can work out a selector to find the menu's final element you want, and then extract the link (or action) from it and either $driver->get() it or use $driver->execute_script('args[0]->click()',$element); to click it regardless of the fact it's not displayed.

On the other hand if your developers were wasteful and create/teardown the DOM nodes on the fly, you are probably screwed.  You'll have to figure out a special workaround to get the effect from the desired action.

Aditya Khaund

unread,
Feb 13, 2018, 2:39:32 AM2/13/18
to Selenium Remote Driver
Thanks for the response. Unfortunately, in my case menus disappear when there is no hovering. I am a little confused with your second comment about using get() or selector. Can you plz explain a more on this? 

Aditya Khaund

unread,
Feb 13, 2018, 2:44:49 AM2/13/18
to Selenium Remote Driver


On Tuesday, 13 February 2018 13:09:32 UTC+5:30, Aditya Khaund wrote:
Thanks for the response. Unfortunately, in my case menus disappear when there is no hovering. I am a little confused with your second comment about using get() or selector. Can you plz explain a more on this? 

Also I am attaching the HTML of the page which contains the menu code . if you see line number 357 there is adminstration which on hovering shows menu -> t114->Manage is the path I want to navigate there basically
test.html
Reply all
Reply to author
Forward
0 new messages