user2526830 user2526830 - 4 months ago 8
Java Question

MouseHover and Click events in Selenium WebDriver

I am trying to do the following events using

Selenium
WebDriver



  • Mousehover
    to Create Application and then

  • Click
    on the New Application



I have following code , the below is a
function


public Boolean entermousehoverandclick(String mousehovervalue , String clickvalue)
{
Boolean status = true;
try
{
WebElement create = driver.findElement(By.linkText(mousehovervalue));

Thread.sleep(2000);

Actions action = new Actions(driver);
action.moveToElement(create).pause(1000).build().perform();

Thread.sleep(1000);

driver.findElement(By.linkText(clickvalue));

Thread.sleep(1000);
}
catch(Exception e)
{
status = false;
}
return status;
}


I am calling the above function in the testcase as below

if(fn.entermousehoverandclick("Create", "New Application"))
{
System.out.println("Successfully clicked on create application");
}
else
{
System.out.println("Error in clicking create application");
}


While running the test case, the script clicks on the create option but it is not selecting the new application option.

Could you please help, thanks in advance.

Answer

After seeing your entermousehoverandclick function, you are going to find "New Application" link but you are not performing any action here. you need to call .click() after successfully find the link "New Application" as below :-

WebElement newApplication = driver.findElement(By.linkText(clickvalue));
newApplication.click();

Hope it will help you..:)

Comments