1

Update: The main problem was that element icon hid a button and it was not clickable. Solution was, using js.Executor, to hide this icon.

I am trying to use Selenium WebDriver for tests, it is new for me, and I have a problem with one element, it is no clickable, I tried find it by linktext, classname, cssselector, it does not work.

I have already read a lot of about this issue "Element is not clickable" , but have not found solution for my test. Hope, you will give me good advice.

Chrome version 67.0.3396.99, 64 bit
Visual C# 2017
Webdriver version 3.13.1.0

Here is my script:

namespace MK_edit
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver(@"C:\Users\alina\ProjectLibre");
            driver.Url = "http://test.test.com"; //not real url, I cannot show it
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60); 
            driver.Manage().Window.Maximize();

            //close popup

            driver.FindElement(By.CssSelector("div.whatsnew-content"));
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            driver.FindElement(By.CssSelector("button.btn.btn-success")).Click(); 
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);

            //edit part

            var lab = driver.FindElement(By.CssSelector("span.glyphicon.glyphicon-edit"));
            lab.Click();


        }

    }
}

Element info:

<li class="allwaysVisible"><a href="#tab-old-edit" data-toggle="tab" title="Map_obj" data-i18n="[title]nav.edit"><span class="glyphicon glyphicon-edit"></span></a></li>

Error message:

Element <span class=\"glyphicon glyphicon-edit\">
</span> is not clickable at point (312, 24). 
Other element would receive the click: <div class=\"modal-backdrop fade\">
</div>\n

Thank you!

Aad Ali
  • 61
  • 5

5 Answers5

1

As per error message you have shared, <div class=\"modal-backdrop fade\"> would recieve the click and not <span class=\"glyphicon glyphicon-edit\">. You cannot interract with your element until div element hovers your element. It means div, if it is a popup or dialogue, should be closed. Or if it is a element which automatically dissapears, you have to wait until this element will be not more visible. Then you can click on your element.

I cannot provide the code sample to solve your issue, since I don't have a link to website. Hope this helps.

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
1

Wait until the spinner/loader disappears, try passing the spinner element ".modal-backdrop" inside a method like this...

        public static void WaitForNotVisible(IWebElement element, IWebDriver driver)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
            wait.Until(drv =>
            {
                try
                {
                    if (element.Displayed)
                    {
                        return false;
                    }
                    return true;
                }
                catch
                {
                    return true;
                }
            });
        }

Like this...

var spinnerElement = driver.FindElement(By.CssSelector(".modal-backdrop"));
WaitForNotVisible(spinnerElement, driver);
labosana.Click();
Taran
  • 491
  • 2
  • 8
  • 22
1

Please add some wait before finding the labosana element

Code:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("span.glyphicon.glyphicon-edit")));

var labosana = driver.FindElement(By.CssSelector("span.glyphicon.glyphicon-edit"));
labosana.Click();
Subburaj
  • 2,294
  • 3
  • 20
  • 37
  • This is the wrong answer! – Rajagopalan Aug 02 '18 at 08:57
  • @Rajagopalan: It could be a right answer.Here,after clicking on the button, some loading popup is getting displayed.so, we need to check the element visibility until the modal popup gets closed. – Subburaj Aug 02 '18 at 09:03
  • Thats the way you it appears and What you explained now is more clear from your answer, but still this is completely wrong. Execute in your system and check it you will come to know what is the problem. – Rajagopalan Aug 02 '18 at 09:05
  • @Rajagopalan: user hasn't shared the URL to test.I am giving the suggestion from my experience. You need to give your valid suggestion , if it is a wrong answer. – Subburaj Aug 02 '18 at 09:10
  • 1
    Selenium doesn't consider the element is invisible when it is overlayed by another element. It's still visible. – Rajagopalan Aug 02 '18 at 09:17
  • Let me check and confirm from myside.Meanwhile, I have changed the expected condition as ElementToBeClickable. – Subburaj Aug 02 '18 at 09:22
  • ElementToBeClickable won't work either. Selenium really doesn't have the way to check whether element is clickable. I wrote an answer for this few days ago , you can read here https://stackoverflow.com/questions/51615508/how-to-check-if-100-covered-webelement-is-clickable-with-selenium/51616760#51616760 – Rajagopalan Aug 02 '18 at 09:26
  • @Rajagopalan: Thanks for the suggestion.But I also had similar problem and it was working perfectly after adding the wait. So, the user can try with this solution and can share their feedback – Subburaj Aug 02 '18 at 16:23
0

You may replace click event with action class,

Actions builder = new Actions(driver);
builder.MoveToElement("Your target element").Click().Perform();
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
0

My element became visible and clickable after such additions, tnx for advices

//open edit

            var lab = driver.FindElement(By.CssSelector("a[title=\"---\"]"));
            var icon = driver.FindElement(By.CssSelector("span.glyphicon.glyphicon-edit"));
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            js.ExecuteScript("arguments[0].style='display: none;'", icon); 

            var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
            wait.Until(ExpectedConditions.ElementToBeClickable(lab));

            lab.Click();
Aad Ali
  • 61
  • 5