-1

we have automated a test, where table columns have been set to hidden (style="...; display:none").

Currently we are using IWebElement.Displayed.

This works fine if the whole table is visible (no scrollbar) but if some columns are scrolled out this don't work. Is there a way to check it without checking the style attribute and without scrolling?

If I would need to use scrolling: how can I check for really invisible columns.

Thank you

  • Execute javascript to compute the effective style? https://stackoverflow.com/questions/32537339/getting-the-values-of-all-the-css-properties-of-a-selected-element-in-selenium – Jeremy Lakeman Mar 17 '22 at 00:40
  • Have you tried `element.GetAttribute("style")` or `element.GetProperty("style")`? – Greg Burghardt Mar 18 '22 at 17:12

3 Answers3

0

You can get the element attribute value with GetAttribute() method.

var style = IWebElement.GetAttribute("style");

Then you will be able to check if style string contains display:none etc.

Prophet
  • 32,350
  • 22
  • 54
  • 79
0

Get element location -

var e = your web element
var elementPosition = new Rectangle(e.Location, e.Size);

Get current screen position

var clientAreaRectangle = new Rectangle(GetScrollOffset(driver), driver.Manage().Window.Size)

public static Point GetScrollOffset(this IWebDriver driver)
{
    var executor = (IJavaScriptExecutor)driver;
    var offset = (Dictionary<string, object>)executor
        .ExecuteScript("return { X: Math.floor(window.pageXOffset), Y: Math.floor(window.pageYOffset) };");
    var offsetX = (int)(long)offset["X"];
    var offsetY = (int)(long)offset["Y"];
    return new(offsetX, offsetY);
}

Check if the element is scrolled into view

clientAreaRectangle.Contains(elementPosition)
shatulsky
  • 306
  • 2
  • 10
0

Irespective of the desired elements being visible / invisible i.e. with style="display: none;", you can select all the table columns using the following locator strategy:

IList<IWebElement> Columns = driver.FindElements(By.XPath("XPathColumnElements"));

You can also induce WebDriverWait for the PresenceOfAllElementsLocatedBy() as follows:

IList<IWebElement> Columns = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.CssSelector("CssSelectorColumnElements")));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352