0

I'm trying to simply hover over an element using Selenium code. The element appears in the web page and it's clickable.

I keep getting this error:

javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite. (Session info: chrome=80.0.3987.132) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'TALANGEL-LP', ip: '172.17.17.148', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_152-release' Driver info: org.openqa.selenium.chrome.ChromeDriver

My code:

WebDriverWait wait = new WebDriverWait(browser,3);
elementToHoverOn = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[id='MyBtn']")));
new Actions(browser).moveToElement(elementToHoverOn).perform();

Even if I try to find the element simply using By.ID I get the same error. I saw on other threads that the element must be specific and it is.

What am I missing here?

Guy
  • 46,488
  • 10
  • 44
  • 88
Tal Angel
  • 1,301
  • 3
  • 29
  • 63
  • 1
    Can you please also share how are you trying to click on element ? I guess above code will only hover over the element. Are you getting the error while hovering over it or while clicking on it ? – Sariq Shaikh Mar 17 '20 at 11:57
  • I have no problem clicking on the element, but I can't hover over it somehow. – Tal Angel Mar 17 '20 at 12:00
  • I am not sure why its failing but can you try alternate way of hovering on it using javascriptexecutor ? Something like this ? JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("document.getElementById('MyBtn').focus();"); – Sariq Shaikh Mar 17 '20 at 12:06
  • @Sariq Shaikh - I tried you code, the problem is that other part of the JavaScript page has errors in it. Is there a way to force the jse to run code? – Tal Angel Mar 17 '20 at 13:11
  • Are there any other locators are present for this web element like class name, type and sometimes web elements will have inner childs and if you observe isClickable attribute in the following child or sibling then use it instead of this web element. can you post the Html code for this web element? It will be easy to answer the question – Dixit_Autobot Mar 17 '20 at 15:17
  • @Dixit_Autobot Answers without code usually get voted down. I need a method that can "eat" anything and will allow me to hover over any element using CSS or Xpath expression. – Tal Angel Mar 17 '20 at 15:45

1 Answers1

1

presenceOfElementLocated() doesn't garuntees that the element is visible. Instead you need to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following Locator Strategies:

  • cssSelector:

    new Actions(browser).moveToElement(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button#MyBtn")))).build().perform();
    
  • xpath:

    new Actions(browser).moveToElement(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@id='MyBtn']")))).build().perform();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The element is visible and clickable, that isn't the issue. – Tal Angel Mar 17 '20 at 12:53
  • The driver seems to be getting a null value for the center of an element.... which suggests that it's size is 0. If this element is showing, you might have another one with the same ID. To test this, catch the exception and then getElements (plural) instead and check the size of the returned array. – pcalkins Mar 17 '20 at 21:35