元素无法点击 - 运行Selenium测试用例时出错

时间:2016-06-10 09:47:32

标签: selenium firefox selenium-webdriver

运行selenium testcases时出现以下错误。 使用firefox 45和selenium-server-standalone 2.52版本。

  

org.openqa.selenium.WebDriverException:元素无法点击   point(62,13.333328247070312)。其他元素将收到点击:

           

(警告:服务器未提供任何堆栈跟踪信息)   命令持续时间或超时:21毫秒构建信息:版本:   ' 2.52.0',修订版:' 4c2593c',时间:' 2016-02-11 19:06:42'系统   信息:主持人:   ' mesos-wl-servicetest-8f2fe7b6-d8bd-429f-abfc-cf5d29242b38',ip:   ' 172.31.6.249',os.name:' Linux',os.arch:' amd64',os.version:   ' 4.4.2-1.el7.elrepo.x86_64',java.version:' 1.8.0_51'司机信息:   org.openqa.selenium.firefox.FirefoxDriver功能   [{applicationCacheEnabled = true,rotate = false,   pageLoadStrategy = fast,handlesAlerts = true,databaseEnabled = true,   version = 45.1.0,platform = LINUX,nativeEvents = false,   acceptSslCerts = false,webStorageEnabled = true,   locationContextEnabled = true,browserName = firefox,   takesScreenshot = true,javascriptEnabled = true,   pageLoadingStrategy = fast,cssSelectorsEnabled = true}]会话ID:   d6ae5f7f-be19-4b79-b248-dfb034d6ce1c at   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:422)     在   org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)     在   org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)     在   org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)     在   org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35)     在org.openqa.selenium.remote.RemoteMouse.click(RemoteMouse.java:59)     在   org.openqa.selenium.interactions.ClickAction.perform(ClickAction.java:37)     在   org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:50)     在org.openqa.selenium.interactions.Actions.perform(Actions.java:373)

3 个答案:

答案 0 :(得分:1)

您应该尝试使用JavascriptExecutor

 WebElement el = driver.findElement....;
 JavascriptExecutor executor = (JavascriptExecutor)driver
 executor.executeScript("arguments[0].click()", el);

希望它能帮助您执行click ...:)

答案 1 :(得分:0)

JavascriptExecutor 点击是一个很好的选项,可以避免元素在点(xx,yy)无法点击。其他元素将收到点击。

您可以使用的另一个替代方法是显式等待以显示该元素

答案 2 :(得分:0)

可能的解决方案可以是..

1)Try to maximize the browser when you are working with resolutions greater than 1024x768. 
             driver.manage().window().maximize();
2) Using  Actions Class
             WebElement element = driver.findElement(By("element"));
             Actions action = new Actions(driver);
             action.moveToElement(element).click().perform();
3) using JavaScriptExecutor
             WebElement el = driver.findElement(By("element"));
             JavascriptExecutor executor = (JavascriptExecutor)driver
             executor.executeScript("arguments[0].click()", el);