click command in selenium webdriver does not work

前端 未结 9 1376
别跟我提以往
别跟我提以往 2020-12-13 09:08

I have just recently done an export of my selenium IDE code to selenium web driver. I have found that a lot of the commands that worked in IDE either fail to work or seleniu

相关标签:
9条回答
  • 2020-12-13 09:24

    If you know for sure that the element is present, you could try this to simulate the click - if .Click() isn't working

    driver.findElement(By.name("submit")).sendKeys(Keys.RETURN);
    

    or

    driver.findElement(By.name("submit")).sendKeys(Keys.ENTER);
    
    0 讨论(0)
  • 2020-12-13 09:25

    WebElement.click() click is found to be not working if the page is zoomed in or out.

    I had my page zoomed out to 85%.

    If you reset the page zooming in browser using (ctrl + + and ctrl + - ) to 100%, clicks will start working.

    Issue was found with chrome version 86.0.4240.111

    0 讨论(0)
  • 2020-12-13 09:35

    A major thing to watch out for is whether a button is Enabled or not. You can still click them and nothing will fall over and the element is there but it is not ready to be clicked on so just doesnt do anything.

    I've been using webdriver and its taken me most of the day to figure this out!

    The following method seems to work reliably (in my environment for one button!)

        private void TryClick(By selector)
        {
            var wait = WaitUpTo(TimeSpan.FromSeconds(10));
            var element = wait.Until(ExpectedConditions.ElementIsVisible((selector)));
    
            //really important bit!
            WaitUpTo(TimeSpan.FromSeconds(5))
                .Until(d => element.Enabled);
    
            element.Click();
        }
    

    you use it something like

    TryClick(By.XPath("//button[contains(.//*,'Some Text')]"));
    
    0 讨论(0)
提交回复
热议问题