I have to click a submenu which is dynamic : (hover on)Menu ->Submenu appears
My selenium code is
element1 =wait.until(ExpectedConditions.elementToBeClickable(By.id("parent_26")));
builder1.moveToElement(element1).clickAndHold(element1).build().perform();
element2=wait.until(ExpectedConditions.elementToBeClickable(driver1.findElement(By.xpath(".//[@id='parentGroup_26']/div[1]/table/tbody/tr/td[1]/div/div[12]/div/a"))));
builder1.moveToElement(element1).clickAndHold(element1).moveToElement(element2).click(element2).build().perform();
During execution, element1 gets clicked and submenu blinks. After executing this there is no error but the element2(i.e submenu ) is not getting clicked.
I have tried using moveToOffset() also but did not work. Please help me out.
I think you are getting into trouble because of clickAndHold method; as the name suggests and as per the use, it clicks (without releasing) at the current mouse location. Hence, the next method in line (as per your code), i.e.,
moveToElement(element2)
is not working.Please try the below code and see if that works for you :
For hovering over element1 and then clicking on element2 in one-go:-
OR
For hovering over element1 first and then clicking on the element2 after that:-
And, just a suggestion. Please try using relative xpaths instead of absolute one. It's much more efficient.