Why hover to element and click submenu does not wo

2019-07-08 05:09发布

问题:

I am working on a page where a left hand main menu has submenus. I try to hover to the main menu item, and it will show the submenu, and then I will click the submenu.

I am using below code:

@FindBy(id = "xxx")
private WebElementFacade mainmenu;

@FindBy(id = "yyy")
private WebElementFacade submenu;

Actions builder = new Actions(getDriver());
builder.moveToElement(mainmenu).perform();
submenu.waitUntilClickable().click();

I've tried other ways like:

action.moveToElement(mainmenu).moveToElement(submenu).click().build().perform();

It seems the problem is: when the test is performed when browser is in full screen, i.e.

driver.manage().window().maximize();

the main menu sometimes flash very quickly as if it's clicked really fast and recede, other times it appears not clicked or hovered to at all.

Because this hover and click active happens immediately after user navigate to the page, I add wait for element on the main menu, but it does not seem to work.

Any ideas how to solve the problem? I do not understand why it happens only when browser is in full screen mode. The only reason I can think of is the main menu element need more time to load.

EDIT:

Btw, the issue is very severe in Chrome. Firefox is better, but not 100% working either. It seems that even a simple hover:

mainmenu.waitUntilPresent();
Actions builder = new Actions(getDriver());
builder.moveToElement(mainmenu)perform();

does not always make the main menu display its submenu. I do not understand why it does not work.