I've been keep on getting NoSuchElementException whenever I try to get an web element. I know that the web element becomes present after some time. So, I've explicitly waited for 5-10 seconds until the web element gets loaded but even then I am still getting NoSuchElementException. Does anyone know how to prevent this exception? Here is my code:
String s=System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver", s+"\\Chrome090615\\chromedriver.exe");
ChromeDriver driver=new ChromeDriver();
try{
driver.manage().window().maximize();
driver.get("http://site21.way2sms.com/content/index.html");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElementByXPath("//*[@id='username']").sendKeys("9XXXXXXXXX");
driver.findElementByXPath("//*[@id='password']").sendKeys("XXXX");
driver.findElementByXPath("//*[@id='loginBTN']").click();
if(driver.findElementByXPath("//*[@id='ebFrm']/div[2]/div[1]/input").isDisplayed()==true)
{
driver.findElementByXPath("//*[@id='ebFrm']/div[2]/div[1]/input").click();
}
else {
new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.id("ebFrm")));
System.out.println("Waiting for 5 secs");
}
boolean ispresent=driver.findElementByXPath("//*[@id='sendSMS']/a").isDisplayed();
driver.findElementByXPath("//*[@id='sendSMS']/a").click();
System.out.println("Clicked sendSms");
driver.findElementByXPath("//*[@id='sendSMS']/a").click();
I'm getting exception for the 'sendSMS' id. Whenever it tries to find this element, it throws NoSuchElementException all the time!