硒点击不总是工作 [英] Selenium click not always working

查看:170
本文介绍了硒点击不总是工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些点击选项卡的测试,但点击并不总是执行。
$ b


  • xpath正如大多数测试时间一样正确


  • 这不是一个时间问题,因为我已经使用thread.sleep()和其他方法来确保元素在点击

  • 之前是可见的。
  • 测试认为它正在执行点击,因为它在执行点击时不会抛出ElementNotFoundException或任何其他异常。由于标签内容不会发生变化,因此在点击后测试失败。


    更多信息
    我使用Selenium 2.44.0来实现在Chrome 44.0上运行的Java测试.2403.107 m。

    是否还有其他的东西可以做,或者这可能是硒的问题?




    • 显式 elementToBeClickable 等待:

        WebDriverWait wait = new WebDriverWait(webDriver,10); 

      WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id(myid)));
      button.click()


    • 点击前移至元素:

       操作actions = new Actions(driver); 
      actions.moveToElement(button).click()。build()。perform();


    • 通过javascript点击:

        JavascriptExecutor js =(JavascriptExecutor)驱动程序; 
      js.executeScript(arguments [0] .click();,button);



    I have some tests which click on a tab, however the click is not always performed.

    • The xpath is correct as most of the times the test works

    • It is not a timing issue as I ve used thread.sleep() and other methods to ensure that the element is visible before clicking

    • The test believes that it is performing the click as it is not throwing an ElementNotFoundException or any other exceptions when 'performing' the click. The test fails later on after the click since the tab content would not have changed.

    Further Info I am using Selenium 2.44.0 to implement tests in Java which run on Chrome 44.0.2403.107 m.

    Is there something else that I can do or could this be an issue with selenium?

    解决方案

    There are several things you can try:

    • an Explicit elementToBeClickable Wait:

      WebDriverWait wait = new WebDriverWait(webDriver, 10);
      
      WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("myid")));
      button.click()
      

    • move to element before making a click:

      Actions actions = new Actions(driver);
      actions.moveToElement(button).click().build().perform();
      

    • make the click via javascript:

      JavascriptExecutor js = (JavascriptExecutor)driver;
      js.executeScript("arguments[0].click();", button);
      

    这篇关于硒点击不总是工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆