How to Hover over and click on an invisible element using selenium webdriver?

前端 未结 6 2023
自闭症患者
自闭症患者 2021-02-02 17:43

There is an invisible element on my HTML page which becomes visible when a mouse hover is done on the element. What I Have to do is

  1. Hover over the element
  2. <
6条回答
  •  醉酒成梦
    2021-02-02 18:29

    Well, after going through your questions numerous times and changing my answers many times I will go with -

    Issue - what I got from the original code -

    You need to move the cursor to the mainMenuBTN (which is visible not the element that becomes visible when you hover the mouse over it ) and subMenuBTN is then displayed which you need to click.

    The only edit to your original code as per me will be adding a statement to move the cursor to your subMenuBTN before you click it. This way works fine for me when I need to click sub menu item.

    Actions builder = new Actions(driver);
    builder.moveToElement(mainMenuBTN).build().perform();
    builder.moveToElement(subMenuBTN).build().perform();
    subMenuBTN.click();
    

    Please let me know if this is the case.

提交回复
热议问题