1

I'm writing a selenium script using java.

In my scenario, I have a select button and a OK button. Select button is enabled and OK button is disabled when I first loaded the page.

When I click on select button, a pop-up window appears. Then I select a date from a date picker in the pop-up window. After selecting the date I click confirm button in the pop-up window. After click on confirm button the pop-up window closes and OK button enables.

This is my test scenario. But, when I run this my test fails at the point of clicking the OK button.

I did lots of research and came up with adding a scroll to my code. Again my test fails at another point (Couldn't select date from the date picker. Cannot imagine how this is happening though.)

Here is my code.

// 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");

Here is the error message I've got.

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)

Can someone tell me a solution for this?

Thanks in advance. :)

Manuli
  • 1,203
  • 4
  • 20
  • 43
  • which website are you testing? is it public? – Akbar Apr 28 '16 at 07:19
  • 2
    These `XPaths` are something bloodcurdling :) You shouldn't use absolute `XPath`! This will not resolve your current problem, but will protect you from future problems :) – Andersson Apr 28 '16 at 07:27
  • @Akbar, sorry it is not public – Manuli Apr 28 '16 at 07:33
  • @Andersson , Thanks. DO u have a solution for current problem ? – Manuli Apr 28 '16 at 07:33
  • @QualityProducts, you can try to apply `WebDriverWait`+`Expected conditions` modules to add waiting time for element to be clickable. But I have no idea how to implement this in `Java` :) – Andersson Apr 28 '16 at 07:39
  • Since you are scrolling down to click on the element, try the options in this post and see if it works. http://stackoverflow.com/questions/12293158/page-scroll-up-or-down-in-selenium-webdriver-selenium-2-using-java – Akbar Apr 28 '16 at 11:30
  • This smells like a timing problem. It sounds like the Date Select Popup is above the OK Button? If Yes: for fast confirmation of a timing problem just do a `Thread.sleep(1000)` after selecting a date. If this works i can write an answer and write an example of how to use the `FluentWait` class – Dude Apr 28 '16 at 14:17
  • Thread.sleep(1000) solved the date picker problem. But, I don't have the solution yet. Yeah! please add an answer. :) – Manuli Apr 29 '16 at 03:55
  • @Dude, I'm still looking for an answer. Can you post ur answer for me? thanx. :) – Manuli May 04 '16 at 07:55
  • @Quality Products sure no problem – Dude May 11 '16 at 12:18

1 Answers1

0

Figured out the answer my self.

Added Thread.sleep(5000); before OK button.

Now my code works as expected. :)

Manuli
  • 1,203
  • 4
  • 20
  • 43