selenium web driver element click not working in windows 10

后端 未结 3 1612
你的背包
你的背包 2021-01-27 02:33

I am using selenium webdriver for automation tool creation in C#. That automation working fine windows 7, but not working windows 10.

ex.

driver.FindElem         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-27 03:00

    Update your browsers and drivers, make sure the browsers and driver version match - you can't use driver version 80 on browser version 70, that is why you get TimeoutException

    That being said,

    There are many reasons why click might not work, some of them:

    1. Element is not intractable.
    2. Other element will receive the click.
    3. For some driver implementations, a bug on some end cases.
    4. Rare - no apparent reason.

    First, try the obvious one (submit, not click)

    driver.FindElement(By.XPath("//button[@type='submit']")).Submit();
    

    If the above didn't work, continue here.

    In order to bypass all the Click() logic, use JavaScript to perform a raw click.

    var element = driver.FindElement(By.XPath("//button[@type='submit']"));
    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", element);
    

    As an extension method

    public static void JavaScriptClick(this IWebElement element)
    {
        // get the driver
        var driver = (IJavaScriptExecutor)((IWrapsDriver)element).WrappedDriver;
    
        // execute the click
        driver.ExecuteScript("arguments[0].click();", element);
    }
    
    // usage
    driver.FindElement(By.XPath("//button[@type='submit']")).JavaScriptClick();
    

    Resources

    You can check Selenium Extensions (open source) for more samples under folder: /src/csharp/Gravity.Core/Gravity.Core/Extensions

    https://github.com/gravity-api/gravity-core

    https://www.nuget.org/packages/Gravity.Core

    If you use C# you can install the package and use it's extensions directly.

    https://www.nuget.org/packages/Gravity.Core/

    Install-Package Gravity.Core
    

提交回复
热议问题