In pilot project getting NoSuchElementException when trying to click on year in calendar | Selenium Forum
J
Jeetendra Singh Posted on 28/05/2023

I have added xpath of year element in properties files. Also added implicit and explicit wait but still not able to select the year that I wanted to select from the year dropdown.

trying to click over here--

 

 

xpath in properties files--


J
Jeetendra Singh Replied on 28/05/2023

I have tried using the below xpaths for the year field but none is working

1-  //select[@data-handler='selectYear']
2-  //select[@class='ui-datepicker-year']
3-  //*[@id='ui-datepicker-div']/div/div/select[2]


J
Jeetendra Singh Replied on 28/05/2023

There was a mistake in writing the xpath, I have not added prop.getproperty line while calling xpath from the properties file. working fine now when corrected. 


P
Paras Gupta Replied on 02/06/2023

//Java code

WebElement year_select = driver.findElement(By.cssSelector(prop.getProperty("year")));
Select year = new Select(year_select);
year.selectByVisibleText(prop.getProperty("years"));

// select month

WebElement month_select = driver.findElement(By.cssSelector(prop.getProperty("month")));
Select month = new Select(month_select);
month.selectByVisibleText(prop.getProperty("months"));

//select date

String desiredNumberString = prop.getProperty("date");
int desiredNumber = Integer.parseInt(desiredNumberString);

String xpathExpression = String.format("//a[@class='ui-state-default'][text()='%d']", desiredNumber);
driver.findElement(By.xpath(xpathExpression)).click();


}


//Properties file

year=#ui-datepicker-div > div > div > select.ui-datepicker-year
month=#ui-datepicker-div > div > div > select.ui-datepicker-month

#data
years=2019
months=Aug
date=16