HTMLDivElement has no size and location

80 views Asked by At

Im trying to automate Google Photos and automatically select some photos depending on filename and timestamp. It works for some items, but not for all. So far it does hit of the search (but always more than one result is presented, so I need to check by timestamp), I hit "click" to select the image, waiting it to be Displayed=true and Enabled=true.

In one iteration inside selections, the Displayed property is set to false (eventhough it is clearly visible in the browser) and I tried to scroll to the element resulting in HTMLDivElement has no size and location. If I try to click directly element not interactable.

Any Ideas about this behavior? The element is visible and enabled.

Here is the code:

public static void HandleSelections(IWebDriver webDriver, IWebElement searchBox, IEnumerable<SelectInfo> selections)
{
    foreach (var item in selections)
    {
        // Search by Filename
        searchBox.SendKeys(Keys.Control + "a");
        searchBox.SendKeys(item.FileName);
        searchBox.SendKeys(Keys.Return);

        // Find all Image DIV elements              
        var elements = webDriver.FindElements(By.CssSelector("div.QcpS9c.ckGgle"));

        // Loop through all elements
        foreach (IWebElement imageDivElement in elements)
        {
            string html = imageDivElement.GetAttribute("outerHTML");
            // Does the HTML code contain the expected timestamp?
            if (html.Contains(item.TimeStamp))
            {
                // Scroll Element to view
                Actions actions = new Actions(webDriver);
                actions.MoveToElement(imageDivElement);
                actions.Perform(); // <-- CRASHES WITH has no size and location

                // Click the element
                var wait = new WebDriverWait(webDriver, TimeSpan.FromMinutes(1));
                var clickableElement = wait.Until(Extensions.ElementIsClickable(imageDivElement));
                clickableElement.Click(); 
                break;
            }
        }
    }
}

Full error message, when trying to click the element, when it is actually visible and clickable in the browser, but the imageDivElement.Displayed property returns false:

OpenQA.Selenium.ElementNotInteractableException
  HResult=0x80131500
  Message=element not interactable
  (Session info: chrome=113.0.5672.127)
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebElement.Execute(String commandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebElement.Click()
   at GooglePhotoGalleryGhostHand.SelectEngine.HandleSelections(IWebDriver webDriver, IWebElement searchBox, IEnumerable`1 selections)

Or when trying to simply scroll (MoveToElement)

OpenQA.Selenium.ElementNotInteractableException
  HResult=0x80131500
  Message=element not interactable: [object HTMLDivElement] has no size and location
  (Session info: chrome=113.0.5672.127)
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.PerformActions(IList`1 actionSequenceList)
   at OpenQA.Selenium.Interactions.Actions.Perform()
   at GooglePhotoGalleryGhostHand.SelectEngine.HandleSelections(IWebDriver webDriver, IWebElement searchBox, IEnumerable`1 selections)

So it keeps telling me it is not displayed or does not have size or location, although I can see and click in the browser by manually.

0

There are 0 answers