About Ternary operator


Consider this scenario...

Let there be a two links which are displayed dynamically at run time. In such cases, we can use ternaray operator.

Below is the sample code.

In the below code at run time there might present either More details or less details and user need to click

WebElement link3 = (driver.findElement(By.linkText("More Details").getText() != null)?driver.findElement(By.linkText("More Details"):driver.findElement(By.linkText("Less Details");
link3.click();

Is same as below


WebElement link3 = if driver.findElement(By.linkText("More Details").getText()!=null {

driver.findElement(By.linkText("More Details");
link3.click();
}
else{
driver.findElement(By.linkText("Less Details")
link3.click();
}

Please refer to this Wikipedia site for more details

http://en.wikipedia.org/wiki/%3F:

Comments

Popular posts from this blog

getting future date

To check if Web Element is present

Clicking a web element on mouse-over