Home > Software engineering >  OpenQA.Selenium.NoSuchElementException: 'no such element c#
OpenQA.Selenium.NoSuchElementException: 'no such element c#

Time:12-02

i have a problem: i can't click one button. selectorshub showed me this: Alert: This element is not interactable through selenium(automation) as it is not visible in UI. Try any near by element. c# I've tried many combinations, please help

driver.FindElement(By.XPath("//a[normalize-space()='Wyloguj']")).Click();

HTML:

<li data-cy="logout-dropdown" class="css-13srz5t"><a href="https://www.olx.pl/account/logout">Wyloguj</a></li>
<a href="https://www.olx.pl/account/logout">Wyloguj</a>

CodePudding user response:

The "Element not interactable" exception occurs when Selenium finds the element, but is unable to click on it. Fixing this usually involves waiting for it to be clickable:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
var element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[normalize-space()='Wyloguj']"));

element.Click();

Since the ExpectedConditions class is deprecated, consider an extension method on WebDriverWait instead:

public static class WebDriverWaitExtensions
{
    public static void Until(this WebDriverWait wait, Action actionToWaitFor)
    {
        wait.Until(driver =>
        {
            actionToWaitFor(driver);

            return true;
        });
    }
}

And to use with your code:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

wait.Until(d => d.FindElement(By.XPath("//a[normalize-space()='Wyloguj']")).Click());

CodePudding user response:

SelectorsHub is showing the info message "This element is not interactable through selenium(automation) as it is not visible in UI." because the element in the web page has zero area so through automation we can't click on that element. If you hover on the DOM node, it will highlight the element in the UI if that element will have some area. Logically we can perform click action on those element only which has some area in webpage. So here you need to check any near by element which has some area and then you can click on that to solve your scenario.

  • Related