0

I want to select a particular date from the calender so I wrote this code with the help of other sources:

WebDriverWait waitForDate = new WebDriverWait(driver,300);
        waitForDate.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='dpTradeDate']/span[@class='add-on']/i[@class='icon-calendar']")));



         driver.findElement(By.xpath("//div[@id='dpTradeDate']/span[@class='add-on']/i[@class='icon-calendar']")).click();


         //WebElement dateWidget=driver.findElement(By.className("datepicker-days"));

         //List<WebElement> rows=dateWidget.findElements(By.tagName("tr"));
         List<WebElement> colmns=driver.findElements(By.tagName("td"));

         /*DatePicker is a table.So navigate to each cell   
           If a particular cell matches value 13 then select it  
          */  


         for (WebElement cell: colmns){  
              //Select 13th Date   
              if (cell.getText().equals("13")){  
              cell.findElement(By.linkText("13")).click();  
              }
         }

Each time I get an execution error message timed out after 300 seconds even though I put an explicit wait for 300 seconds. I guess this code is valid for picking up a particular date.

1

If you're timing out, the WebdriverWait probably isn't finding anything - maybe a glitch in the XPath?

Try validating it manually on the page. In the Chrome console, you can just use:

$x("xpath here")

Does that render any result?

(I would've commented rather than replied, but I'm short two reputation points.)

| improve this answer | |
0

even though I put an explicit wait for 300 seconds

Your code does not wait for 300 seconds. Your code waits until the element located by the xpath statement "//div[@id='dpTradeDate']/span[@class='add-on']/i[@class='icon-calendar']" is visible. If it is not visible after 300 seconds, it throws the exact error you're seeing: timed out after 300 seconds. Therefore, your xpath is not pointing to a visible element.

Debug your xpath statement and your problem will be solved :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.