WebDriver - element is not clickable Chrome

前端 未结 8 1144
攒了一身酷
攒了一身酷 2021-02-04 10:56

I have following problem. I run test on Firefox and Chrome. On Firefox test run correctly but on Chrome SauceLabs give a message:

unknown error: Element is not          


        
8条回答
  •  失恋的感觉
    2021-02-04 11:12

    Since you've tagged the question as Google-Chrome too - I suppose that this is happening mostly with ChromeDriver. I had the same issues with one of my previous projects (Asp .Net MVC). I found that when some elements are not visible for this Driver if they are not in the screen_visible_area. Please note that they are loaded (HTML, CSS3, JS etc.) properly.

    So after a lot of reading and testing, I found that my workaround is simply scroll to the WebElement - so it is in the visible part of the screen. Actually this issue was not for all elements and I didn't find better solution for it.

    unknown error: Element is not clickable at point (..., ...) 
    

    Is not descriptive error for this case, because like you I also thought that is Selector-related.

    Just to be full answer - I had the same problems with IEDriver too. My implementation was to use the Browser scroll down/up options and just "send the screen" where the problematic element is.

    Simple JSExecutor code that you can use:

    WebDriver driver = new FirefoxDriver();
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("window.scrollBy(110,350)", "");
    

    or

    jse.executeScript("scroll(0, 250);");
    

    or

    driver.executeScript("window.scrollBy(110,350)", "");
    

    Other topic-related useful resources are here.

    Update

    When it comes to the .sendKeys() I also used the browser accessibility features. All you need to do is just count how many TAB clicks your test need in order to get to the targeted web_element. Then just call .click().

    Try this simple code:

    element.sendKeys(Keys.TAB);
    

    or

    element.sendKeys("\t")
    

    or

    Actions builder = new Actions(driver);
    builder.keyDown(Keys.TAB).perform()
    

提交回复
热议问题