Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium how to make click and hold button

In webpage I test is a modal which appears after pressing a button for circa 5sec.

And now I'm trying to make this in selenium. I have method like this:

public static void ClickHold(IWebElement by)
{
    SpecialInteractions.ClickAndHold(by);
}

where

public static Actions SpecialInteractions { get; set; }

and there is no hold time to set.

It looks like just clicking and releasing. Is there a way to wait for particular amount of time and then release?

like image 837
szpic Avatar asked Aug 31 '25 00:08

szpic


1 Answers

Without digging dipper I can tell you the program above probably returns NulReference exception. I suspect you need to instantiate the Actions by wrapping the current driver instance.

Possible solution could be:

public void ClickHold(IWebElement element)
{
    Actions action = new Actions(driver);
    action.clickAndHold(webelement).build().perform();
    //you need to release the control from the test
    //actions.MoveToElement(element).Release();
}
like image 88
Saifur Avatar answered Sep 02 '25 16:09

Saifur