How to hover over a hyperlink - Webdriver

I am using Selenium Webdriver for my project. I already automated the code for the mouse over the image, which was done successfully. But, some, like I couldn’t lure a hyperlink with this code.

The code I used was

Actions build1 = new Actions(driver); build1.moveToElement(WebElement).build().perform();

I also tried using

Locatable hoverItem = (Locatable) driver.findElement(); Mouse mouse = ((HasInputDevices) driver).getMouse(); mouse.mouseMove(hoverItem.getCoordinates())

But it also does not work. Please help me on this.

+4
source share
4 answers

I had the same problem and it was solved by moving the cursor 1px. The last line raised the hover event.

 Actions action = new Actions(driver); action.moveToElement(element).build().perform(); action.moveByOffset(1, 1).build().perform(); 
+1
source

Try the following:

 Actions action = new Actions(webdriver); WebElement we = webdriver.findElement(By.xpath("x_p_a_t_h")); action.moveToElement(we).build().perform(); 
0
source

I used the public void mouseOver(String) method in the DefaultSelenium class. The essence of the code is as follows:

 protected void hoverAction() { WebDriverBackedSelenium webDriver = some_elaborate_method_to_get_webdriver; webDriver.mouseOver("x_p_a_t_h"); } 

You may also need to peek at some time to wait for your freeze to make sure that the item gets rendered before the crash (for example, drop-down menus that are usually launched from links are not displayed instantly).

0
source

All the other posters published all the offers that I could come up with, and yet no one works. When I get to this point, I will take a step back and ask why I need to hover over the hyperlink. Is it just checking the text? If this happens, I would use element.getAttribute ("alt") and just check the text that I was expecting. I do not need to check browser freeze functionality. The only thing I could suggest is to make sure that the mouse cursor is not in the browser window when starting the test. It can also reset the mouse.

0
source

Source: https://habr.com/ru/post/1494529/


All Articles