Debugging “Element is not clickable at point” error

后端 未结 30 2567
余生分开走
余生分开走 2020-11-21 23:55

I see this only in Chrome.

The full error message reads:

\"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675

30条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 00:32

    First, try to get the latest Chrome driver and check if it solves the issue.

    In my case, it didn't fix the issue. But, the following solution worked for me so far. The following is C# code but you can follow same logic in your specific language. What we do here is,

    Step 1: Focus on the element using the Selenium Actions object,

    Step 2: Then do a click on the element

    Step 3: If there's an exception, then we trigger a javascript "Click" event on the element by executing the javascript script through the Selenium browser driver's "ExecuteScript" method.

    You can also skip step 1 and 2 and try only step 3 too. Step 3 would work on it's own but I noticed some strange behavior in one scenario in which step 3, even though it successfully clicked the element, caused unexpected behavior in other parts of my code after clicking the element.

                try
                {
                    //Setup the driver and navigate to the web page...
                    var driver = new ChromeDriver("folder path to the Chrome driver");
                    driver.Navigate().GoToUrl("UrlToThePage");
    
                    //Find the element...
                    var element = driver.FindElement(By.Id("elementHtmlId")); 
    
                    //Step 1
                    new Actions(driver).MoveToElement(element).Perform();  
    
                    //Step 2
                    element.Click();
                }
                catch (Exception)
                {
                    //Step 3
                    driver.ExecuteScript("document.getElementById('elementHtmlId').click();");
    
                }
    

提交回复
热议问题