if(!driver.findElement(By.id("pt1:r1:0:r1:2:r1:0:it1::content")).isEnabled())
{
System.out.println("IS NOT DISPLAYED"); // if text box is display
driver.findElement(By.id("pt1:r1:0:r1:2:next")).click();
}
else if(driver.findElement(By.id("pt1:r1:0:r1:2:r1:0:it1::content")).isEnabled())
{
System.out.println("IS DISPLAYED"); // if text box is not display
driver.findElement(By.id("pt1:r1:0:r1:2:r1:0:it1::content")).sendkey("ABCXYZ");
driver.findElement(By.id("pt1:r1:0:r1:2:next")).click();
}
I have tried with try and catch block its working but it takes time to execute script.
Simply explained, what you want to do is: 1. check if the textbox exists on the page... if it exists, put text in it. 2. click the next button.
Whether or not the checkbox exists, you still click on the next button so pull that outside your if
.
List<WebElement> textboxes = driver.findElements(By.id("pt1:r1:0:r1:2:r1:0:it1::content"));
if (!textboxes.isEmpty())
{
// textbox exists
textboxes.get(0).sendKeys("ABCXYZ");
}
driver.findElement(By.id("pt1:r1:0:r1:2:next")).click();
If you are going to reuse the locators ( By
s), I would suggest that you store them in a variable, eg
By nextButtonLocator = By.id("pt1:r1:0:r1:2:next");
driver.findElement(nextButtonLocator).click();
I would suggest that you read some tutorials on Java programming to improve your programming knowledge. There are some really good Java books you can get also.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.