java - Selenium 中的元素在 (X, Y) 点不可点击

标签 java selenium

我正在使用java编写一个selenium脚本。

在我的场景中,我有一个选择按钮和一个确定按钮。当我第一次加载页面时,选择按钮已启用,确定按钮已禁用。

当我单击选择按钮时,会出现一个弹出窗口。然后我从弹出窗口中的日期选择器中选择一个日期。选择日期后,我单击弹出窗口中的确认按钮。单击“确认”按钮后,弹出窗口关闭,“确定”按钮启用。

这是我的测试场景。但是,当我运行此命令时,我的测试在单击“确定”按钮时失败了。

我做了很多研究,并想出在我的代码中添加一个滚动条。我的测试再次在另一个点失败(无法从日期选择器中选择日期。但无法想象这是如何发生的。)

这是我的代码。

// Click Select button
driver.findElement(By.xpath("//tr[@id='0']/td[2]/a")).click(); 
System.out.println("User Clicked Select button");

// Select Days
driver.findElement(By.xpath("//div[@id='myModal0']/div/div/div[2]/div/div[2]/div/div/input")).click();
driver.findElement(By.xpath("//div[@id='ui-datepicker-div']/table/tbody/tr[5]/td[7]/a")).click(); 
System.out.println("User Selected the days the service is offered");

// Click Confirm Button
driver.findElement(By.xpath("//div[@id='myModal0']/div/div/div[2]/div/div[6]/button")).click(); 
System.out.println("User clicked Confirm Button");

// Page Scroll
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");

// Click OK Button
driver.findElement(By.xpath("/html/body/div[1]/div[4]/div/div[2]/table/tbody/tr[1]/td[6]/button")).click();
System.out.println("User Clicked OK Button");

这是我收到的错误消息。

Exception in thread "main" org.openqa.selenium.WebDriverException: Element is not clickable at point (1460.7666015625, 159.03334045410156). Other element would receive the click: Command duration or timeout: 89 milliseconds Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58' System info: host: 'ET_LAHIRU', ip: '192.168.1.4', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_25' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: fea6e350-638c-4cb6-8136-79010aec01a4 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85) at selrcdemo.Activities.activities(Activities.java:73) at selrcdemo.ayubomain.main(ayubomain.java:69)

有人可以告诉我这个问题的解决方案吗?

提前致谢。 :)

最佳答案

我自己找到了答案。

在“确定”按钮之前添加了 Thread.sleep(5000);

现在我的代码可以按预期工作。 :)

关于java - Selenium 中的元素在 (X, Y) 点不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36906262/

相关文章:

python - 如何在 Python-Selenium 的 Xpath 中传递带有撇号 (') 的字符串变量?

python - 如何使用 Selenium 和 Python 绕过 Google 验证码?

java - 父类(super class)的调用方法

java - 接口(interface)隐式声明 Object 类的公共(public)方法?

java - Struts application.properties 文件不支持重音字符

ruby - 如何将 headless Chrome 与 capybara 和 Selenium 一起使用

java - 我试图从下拉列表中选择值,但我不能为什么?

python - selenium - chromedriver 可执行文件需要在 PATH 中

java - 为什么我无法访问java中内部类的方法?

java - 想学习Maven