Currently, I am in the process of learning Selenium Webdriver and working on a code to populate a registration form for rediff.com. When opting for a rediffmail ID, there is a validation button that checks if the entered ID is available or not. If the chosen ID is indeed available, I would like the code to automatically complete the remaining fields on the page. However, if the ID is unavailable, the process should halt and prompt the user to select a new ID. I have managed to develop some code to achieve this functionality, but I believe there might be a better approach. Therefore, seeking advice from experts on the matter. Below is the code snippet. Appreciate any assistance provided.
public void fillformredifflocators() {
try {
invokebrowser("http://register.rediff.com/register/register.php?FormName=user_details");
driver.findElement(By.xpath("/html/body/center/form/div/table[2]/tbody/tr[3]/td[3]/input")).sendKeys("Rediff User");
driver.findElement(By.xpath("/html/body/center/form/div/table[2]/tbody/tr[7]/td[3]/input[1]")).sendKeys("abcd540");
driver.findElement(By.className("btn_checkavail")).click();
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
String expectedMessage = "Yippie! The ID you've chosen is available.";
String Message = driver.findElement(By.xpath("//b[contains(text(),\"Yippie! The ID you've chosen is available.\")]")).getText();
Assert.assertEquals(Message, expectedMessage);
if (expectedMessage.equals(Message))
{
System.out.println("Congrats ! Your chosen id can be used");
}
else
{
System.out.println("Please use a different id as the chosen id is taken");
}
driver.findElement(By.xpath("/html[1]/body[1]/center[1]/form[1]/div[1]/table[2]/tbody[1]/tr[9]/td[3]/input[1]")).sendKeys("password123");
} catch (Exception e) {
e.printStackTrace();
}
}