Is there any way to use Selenium to Simulate mouse over an webElement for 5 seconds?

5,231 views
Skip to first unread message

likefo...@gmail.com

unread,
Nov 6, 2011, 10:06:53 AM11/6/11
to Selenium Users
'move_to_element' is Moving the mouse to the middle of an element, but
it return to the The original location
Immediately.Maybe less than one second。

Is there any way to use Selenium to simulate mouse over an element
for a few seconds(for example: 5 seconds)?

santosh h s

unread,
Nov 6, 2011, 12:25:58 PM11/6/11
to seleniu...@googlegroups.com
you can use selenium mouseover  API and give 5 seconds delay after that



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--

/Santosh

likefo...@gmail.com

unread,
Nov 7, 2011, 10:12:31 AM11/7/11
to Selenium Users
selenium mouseover API can't be used in webdriver. And i found that
mouseover API have no argument for delay second.

code:
ac = webdriver.ActionChains(driver)
ac.move_to_element(uncare_parent_list[0])
ac.click()
ac.perform()

It triggered mouseout event Immediately after the code excuted. it is
not expected. Instead, is there any way to keep the mouseover event
after the move_to_element excute?




On 11月7日, 上午1时25分, santosh h s <santosh.s...@gmail.com> wrote:
> you can use selenium mouseover  API and give 5 seconds delay after that
>
> On Sun, Nov 6, 2011 at 8:36 PM, likeforev...@gmail.com <

Moises Siles

unread,
Nov 7, 2011, 10:13:32 AM11/7/11
to seleniu...@googlegroups.com
Are you using Webdriver or Selenium RC o Selenium IDE??/



ke li

unread,
Nov 7, 2011, 10:16:38 AM11/7/11
to seleniu...@googlegroups.com
using Webdriver . python api.

2011/11/7 Moises Siles <moises...@gmail.com>

Moises Siles

unread,
Nov 7, 2011, 10:30:36 AM11/7/11
to seleniu...@googlegroups.com
you can do something like this in order to execute the mouseover action

                Actions builder = new Actions(webDriver);
                builder.MoveToElement(webElement).Perform();

ke li

unread,
Nov 7, 2011, 10:37:15 AM11/7/11
to seleniu...@googlegroups.com
thank you for help. it triggered mouseover event using MoveToElement, but it triggered mouseout event Immediately after mouseover excute.

2011/11/7 Moises Siles <moises...@gmail.com>

Luke Inman-Semerau

unread,
Nov 7, 2011, 11:06:01 AM11/7/11
to seleniu...@googlegroups.com
I think you can get what you want by doing this:

ActionChains(driver).click_and_hold(el).perform()

If you want to actually click on that element after verifying the other items on the page, then just release the mouse:

ActionChains(driver).release(el).perform()

Otherwise I think you can get away with not releasing and performing whatever action you want to next.

Mark Collin

unread,
Nov 7, 2011, 11:32:20 AM11/7/11
to seleniu...@googlegroups.com
Once moved it should stay in place...

Sounds silly but you aren't knocking the mouse during the test are you?
Possible bug?


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Jim Evans

unread,
Nov 7, 2011, 12:11:22 PM11/7/11
to Selenium Users
It's important to know what browser you are seeing this in. There is a
known issue in IE that if the physical mouse cursor is within the
browser window when you are trying the MoveToElement, you'll see
exactly this behavior. There isn't really any way for WebDriver to
work around it that I've been able to find; it looks like part of IE's
internal mouse cursor hit test tracking. Nevertheless, if it's IE
you're seeing this on, try the test making sure the physical mouse
cursor is not within the browser window.

--Jim

On Nov 7, 7:37 am, ke li <likeforev...@gmail.com> wrote:
> thank you for help. it triggered mouseover event using MoveToElement, but
> it triggered mouseout event Immediately after mouseover excute.
>
> 2011/11/7 Moises Siles <moises.si...@gmail.com>
>
>
>
>
>
>
>
> > you can do something like this in order to execute the mouseover action
>
> > Actions builder = new Actions(webDriver);
> > builder.MoveToElement(webElement).Perform();
>
> > On Mon, Nov 7, 2011 at 9:16 AM, ke li <likeforev...@gmail.com> wrote:
>
> >> using Webdriver . python api.
>
> >> 2011/11/7 Moises Siles <moises.si...@gmail.com>
>
> >>> Are you using Webdriver or Selenium RC o Selenium IDE??/
>

Mike

unread,
Nov 7, 2011, 1:14:36 PM11/7/11
to Selenium Users
This can be done using WebDriverBackedSelenium in a WebDriver
environment. I do it myself all the time, so I know it is possible
using WebDriver, but I don't know how it gets implemented behind the
scenes. I implemented my own wrapper routine that checks for the
element I expect to be made visible being made visible and have it
throw an exception if it does not within a certain period.

// This is in my base class:
public WebDriverBackedSelenium selenium;

// Right after I succeed in creating the WebDriver session I do this:
selenium = new WebDriverBackedSelenium(driver, baseUrlString);

// This allows you to specify the time to wait for the element to
become visible (the timer is already created earlier):
public void mouseOverAndWait(String hoverLocator, String
waitLocator,
int timeout) throws Exception
{
boolean firstTime = true;

selenium.mouseOver(hoverLocator);
timer.setInitialDelay(timeout); // Set timer for 5
seconds...
timer.start();

while (!selenium.isVisible(waitLocator))
{
if (firstTime)
firstTime = false; // Don't pause the first time, just
in case
else
{
if (timerExpired)
{
throw new Exception(waitLocator +
" never became visible after
hovering" +
"over " + hoverLocator);
}
else
Thread.sleep(50); // Pause and check every .05
second
}
}

timer.stop();
} // mouseOverAndWait(String hoverLocator, String waitLocator)

// This is the more typical routine used, with a default of 5 seconds:
public void mouseOverAndWait(String hoverLocator, String
waitLocator) throws
Exception
{
mouseOverAndWait(hoverLocator, waitLocator, 5000);
} // mouseOverAndWait(String hoverLocator, String waitLocator)

I hope that helps you.

Mike


On Nov 7, 7:12 am, "likeforev...@gmail.com" <likeforev...@gmail.com>
wrote:

ke li

unread,
Nov 8, 2011, 12:13:34 AM11/8/11
to seleniu...@googlegroups.com
Thanks  for all your help . I updated issue status.

1. I used firefox 7.0.1.
2. It is a bad news that python api don't support WebDriverBackedSelenium. so...
3. I tried click_and_hold, but still can't work properly.

Is there really no way to workaround the limitation?


2011/11/8 Mike <lvsk...@cox.net>

Mike

unread,
Nov 8, 2011, 1:49:15 PM11/8/11
to Selenium Users
Well I don't know the Python implementation (or Python for that
matter), but looking into how WebDriverBackedSelenium is implemented I
see that mouseOver is mapped with this statement in
WebDriverCommandProcessor.java:

seleneseMethods.put("mouseOver", new MouseEvent(elementFinder,
javascriptLibrary, "mouseover"));

The MouseEvent constructor appears to be simply be executing some
JavaScript:

public MouseEvent(ElementFinder elementFinder, JavascriptLibrary js,
String type) {
this.elementFinder = elementFinder;
this.js = js;
fire = "return (" + js.getSeleniumScript("fireEvent.js") +
").apply(null, arguments);";
this.type = type;
}

I believe the command actual gets executed by this routine:

protected Void handleSeleneseCommand(WebDriver driver, String
locator, String value) {
WebElement element = elementFinder.findElement(driver, locator);

js.executeScript(driver, fire, element, type);

return null;
}

So if you can do the equivalent in Python to what is being done here
in Java you should be able to perform the same function as I am using.

That should give you enough info to write the equivalent Python code,
I hope. If it does, post it here for others to see, please.

Mike

On Nov 7, 9:13 pm, ke li <likeforev...@gmail.com> wrote:
> Thanks for all your help . I updated issue status.
>
> 1. I used firefox 7.0.1.
> 2. It is a bad news that python api don't support WebDriverBackedSelenium.
> so...
> 3. I tried click_and_hold, but still can't work properly.
>
> Is there really no way to workaround the limitation?
>
> 2011/11/8 Mike <lvskip...@cox.net>

ke li

unread,
Nov 15, 2011, 1:15:03 AM11/15/11
to seleniu...@googlegroups.com
thanks very much for Mike 's help! the code worked now.

Mike

unread,
Nov 15, 2011, 12:21:48 PM11/15/11
to Selenium Users
Glad I was able to help. How about posting your working code here for
other Python users to see.

Mike

On Nov 14, 10:15 pm, ke li <likeforev...@gmail.com> wrote:
> thanks very much for Mike 's help! the code worked now.
>

Dawei

unread,
Jan 4, 2012, 6:22:08 AM1/4/12
to Selenium Users
So what's the final solution for this issue?

On Nov 16 2011, 1:21 am, Mike <lvskip...@cox.net> wrote:
> Glad I was able to help. How about posting your working code here for
> other Python users to see.
>
> Mike
>
> On Nov 14, 10:15 pm, ke li <likeforev...@gmail.com> wrote:
>
> > thanks very much for Mike 's help! the code worked now.
>
> > 在 2011年11月9日 上午2:49,Mike <lvskip...@cox.net>写道:
>
> > > Well I don't know the Python implementation (or Python for that
> > > matter), but looking into how WebDriverBackedSelenium is implemented I
> > > see thatmouseOveris mapped with this statement in
> > > > >selenium= new WebDriverBackedSelenium(driver, baseUrlString);
> > > > > >seleniummouseover API can't be used in webdriver. And i found that
> > > > > >mouseover API have no argument for delay second.
>
> > > > > > code:
> > > > > > ac = webdriver.ActionChains(driver)
> > > > > > ac.move_to_element(uncare_parent_list[0])
> > > > > > ac.click()
> > > > > > ac.perform()
>
> > > > > > It triggered mouseout event Immediately after the code excuted. it is
> > > > > > not expected. Instead, is there any way to keep themouseoverevent
> > > > > > after the move_to_element excute?
>
> > > > > > On 11月7日, 上午1时25分, santosh h s <santosh.s...@gmail.com> wrote:
>
> > > > > > > you can useseleniummouseover API and give 5 seconds delay after
> > > that
>
> > > > > > > On Sun, Nov 6, 2011 at 8:36 PM, likeforev...@gmail.com <
>
> > > > > > > likeforev...@gmail.com> wrote:
> > > > > > > > 'move_to_element' is Moving the mouse to the middle of an
> > > element,
> > > > > but
> > > > > > > > it return to the The original location
> > > > > > > > Immediately.Maybe less than one second。
>
> > > > > > > > Is there any way to useSelenium to simulate mouse over an
> > > element
> > > > > > > > for a few seconds(for example: 5 seconds)?
>
> > > > > > > > --
> > > > > > > > You received this message because you are subscribed to the
> > > Google
> > > > > Groups
> > > > > > > > "SeleniumUsers" group.
> > > > > > > > To post to this group, send email to
> > >seleniu...@googlegroups.com
> > > > > .
> > > > > > > > To unsubscribe from this group, send email to
> > > > > > > >selenium-user...@googlegroups.com.
> > > > > > > > For more options, visit this group at
> > > > > > > >http://groups.google.com/group/selenium-users?hl=en.
>
> > > > > > > --
>
> > > > > > > /Santosh
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "SeleniumUsers" group.
> > > > > To post to this group, send email toseleni...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > >selenium-user...@googlegroups.com.
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/selenium-users?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "SeleniumUsers" group.
> > > To post to this group, send email toseleni...@googlegroups.com.
Message has been deleted
Message has been deleted
Message has been deleted

Dawei

unread,
Jan 4, 2012, 7:22:21 AM1/4/12
to Selenium Users
Hi Mike,

If using the method handleSeleneseCommand, how to define the variable
'type'?

Thanks
> > > > > > >mouseoverAPI have no argument for delay second.

saheb kanodia

unread,
Feb 6, 2014, 12:53:21 AM2/6/14
to seleniu...@googlegroups.com
I am having a similar issue. Could you please post your code [python].
Reply all
Reply to author
Forward
0 new messages