I am grappling with a challenge in my Selenium testcase as a temporary CSS element is blocking the xpath element I need to click on.
During the execution of my testcase in Visual Studio, I encounter an error message that reads:
OpenQA.Selenium.ElementClickInterceptedException Element <a href="#/app/customer/handling/devices"> is not clickable at point (105,221) because another element <div class="showbox layout-align-center-center layout-row ng-star-inserted"> obscures it
The obstructing element appears to be a CSS object. However, upon manual inspection and search for this specific CSS element
<div class="showbox layout-align-center-center layout-row ng-star-inserted">
, no results are found in the code.
This leads me to believe that the CSS element is transient and only detectable for a short period while the page loads. This theory is supported by the fact that inserting a static wait method Task.Delay(4000).Wait();
enables the successful completion of the testcase.
Yet, I am not inclined towards using a static wait method as a solution in my code. I aim to await the disappearance of the temporary CSS to proceed with clicking on my desired xpath element.
Presented below is the relevant section of my code:
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("div class='showbox layout-align-center-center layout-row ng-star-inserted'")));
//Waiting for temporary CSS element to appear
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.CssSelector("div class='showbox layout-align-center-center layout-row ng-star-inserted'")));
//Waiting for temporary CSS element to vanish
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div/div[2]/nav[2]/div/ul/li[1]/a"))).Click();
//Click on the "Handle Tools" link
In executing the above actions, I encounter an error regarding the invalidity of the CSS selector I am trying to locate.
If I skip the initial step and directly wait for the CSS to disappear or become "invisible," the check happens too swiftly, preceding the loading of the CSS element.
Hence, there might be an issue in how I am defining the By.CssSelector format or possibly, the CSS element carries a different name than indicated in the error message from Visual Studio mentioned earlier.
I seek guidance on whether my approach to identifying the CSS element here is incorrect:
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.CssSelector("div class='showbox layout-align-center-center layout-row ng-star-inserted'")));
ALTERNATIVELY
Is there a preferable technique to dynamically waiting out transient CSS elements?
OR
Can I verify if the CSS element hindering the action is truly denoted as "div class='showbox layout-align-center-center layout-row ng-star-inserted'"?