WebDriver - element is not clickable Chrome

前端 未结 8 1141
攒了一身酷
攒了一身酷 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:05

    I realize this is a super old question, but it came up while searching a nearly identical problem in the present day. After attempting many of the fixes described here and getting new exceptions for my trouble (mostly stale element and http request timeouts) I stumbled across this issue on Selenium's GitHub.

    As described in the post, Chrome had advanced beyond the abilities of my version of chromedriver.exe--my v2.30 driver had known issues with clicking elements due to changes in Chrome v61 scrolling mechanics. Updating to the latest chromedriver.exe solved all my problems.

    tl/dr: ensure your version of chromedriver is compatible with the version of Chrome being tested.

    0 讨论(0)
  • 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()
    
    0 讨论(0)
  • 2021-02-04 11:14

    I was getting issue that login button is not clickable in chrome even xpath was correct. after browsing many sites, i came to the solution - use .submit() instead of .click() and it worked perfectly.

    driver.findElement(By.xpath("//button[@id='loginBtn']")).click();
    driver.findElement(By.xpath("//button[@id='loginBtn']")).submit();
    
    0 讨论(0)
  • 2021-02-04 11:17

    I. If the button is on the bottom of the page, the following code could be used to get you to the bottom via JavaScript from where the click can be executed:

    (driver as IJavaScriptExecutor).ExecuteJavaScript("window.scrollTo(0,document.body.scrollHeight - 150)");

    The same action could be done via C# with the Actions class provided by Selenium. This will get you to the bottom of the page----->

    new Actions(Driver).SendKeys(Keys.End).Perform();

    Keys.End could be switched with Keys.PageDown // Keys.Space

    II. If you want to get to the exact position of the element you can:

    1.Get the element's Y location---> var elementToClick = driver.findElement(By.{Anything}(""));

    2.Execute the following JS---> (driver as IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,{0})", elementToClickYLocation.Location.Y));

    3.Click the element---> elementToClick.click();

    0 讨论(0)
  • 2021-02-04 11:19

    If you're doing anything complicated in your CSS, Chrome can get confused (this has happened to me) and think that the element you're trying to click is covered by another element even though this is not the case.

    One way to resolve this is to help Chrome understand the situation correctly by adding z-indexes (you'll need to add relative or absolute positioning also) to unambiguously place the correct element on top of the other.

    0 讨论(0)
  • 2021-02-04 11:21

    I have had this problem on FF. This issue happens when your field is not in the view area. The slick way to resolve this issue is to zoom out your browser:

    TheNotClickableField.SendKeys(Keys.Control + "-" + "-");

    you might want to zoom out more or less according to your page size.

    0 讨论(0)
提交回复
热议问题