Hi,
If I am not using Thread.sleep(2000) then I am getting element not found exception
Its working properly when i add Thread.sleep(2000).
PFB the code :-
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ICICI_Bank {
public static void main(String args[]) throws ParseException, InterruptedException
{
String day_str = null;
String year_date="09/12/1950";
Date date=new SimpleDateFormat("dd/MM/yyyy").parse(year_date);
int year = Integer.parseInt(new SimpleDateFormat("yyyy").format(date));
String month = String.valueOf((new SimpleDateFormat("MMM").format(date)));
int day = Integer.parseInt(new SimpleDateFormat("dd").format(date));
if (day<10)
{
day_str ="0"+day;
}
System.out.println(year+ " ---"+month+"----"+day_str);
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://loan.icicibank.com/asset-portal/auto-loan/check-eligibility?WT");
driver.findElement(By.xpath("//img[@ng-src='assets/images/calendar.svg']")).click();
while(true)
{
String displayed_year=driver.findElement(By.xpath("//button[starts-with (@id,'datepicker')]/strong")).getText();
int lower_date=Integer.parseInt(displayed_year.split(" - ")[0]);
System.out.println(lower_date);
int upper_date=Integer.parseInt(displayed_year.split(" - ")[1]);
System.out.println(upper_date);
if ((year>=lower_date) && (year<=upper_date))
{
//*[@id="datepicker-423-115-2"]/button
Thread.sleep(2000);
//driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.findElement(By.xpath("//span[text()='"+year+"']")).click();
//Thread.sleep(2000);
driver.findElement(By.xpath("//span[@class='ng-binding' and text()="+"'"+month+"'"+"]")).click();
driver.findElement(By.xpath("//span[text()='"+day_str+"']")).click();
break;
}
else if(year<lower_date)
{
Thread.sleep(2000);
driver.findElement(By.xpath("//i[@class='glyphicon glyphicon-chevron-left']")).click();
}
else
{
Thread.sleep(2000);
driver.findElement(By.xpath("//i[@class='glyphicon glyphicon-chevron-right']")).click();
}
}
}
}
Exception -
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <i class="glyphicon glyphicon-chevron-left"></i> is not clickable at point (879, 544). Other element would receive the click: <span ng-class="::{'text-info': dt.current}" class="ng-binding">...</span>
(Session info: chrome=75.0.3770.100)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'AA-PC', ip: '172.20.10.4', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_211'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.90 (a6dcaf7e3ec6f..., userDataDir: C:\Users\aa\AppData\Local\T...}, goog:chromeOptions: {debuggerAddress: localhost:60267}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 7e187b3e60c69a4d8364ba8421d436eb
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at ICICI_Bank.main(ICICI_Bank.java:54)
Instructor
Ashish Thakur Replied on 08/07/2019
With the help of Exception log, can see that the XPath you are trying to locate the element is not effective.
Please try generating your own custom XPath.
But how come its working properly if i add Thread.sleep in the code if xpath is not effective?
Instructor
Ashish Thakur Replied on 11/07/2019
Sometimes the contents of the page are loaded later on with the help of AJAX call. To handle such a situation, you need to wait for the element to become available.