Search This Website

Monday, 23 May 2022

Fluent Wait in Selenium Webdriver Java with Example | Fluent Wait vs Implicit Wait vs Explicit Wait

                  In this video. we will see Fluent Wait in Selenium Webdriver Java with Example | Fluent Wait vs Implicit Wait vs Explicit Wait 


Program Code:

import java.util.concurrent.TimeUnit;

import java.util.function.Function;


import org.openqa.selenium.By;

import org.openqa.selenium.NoSuchElementException;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.FluentWait;

import org.openqa.selenium.support.ui.Wait;

import org.openqa.selenium.support.ui.WebDriverWait;


import java.time.Duration;


public class FluentWaitExample {


@SuppressWarnings("deprecation")

public static void main(String[] args) throws InterruptedException 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://in.bookmyshow.com/explore/movies-pune");

driver.manage().window().maximize();

//driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));

//WebDriverWait w =new WebDriverWait(driver, Duration.ofSeconds(5));

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)

       .withTimeout(Duration.ofSeconds(30))

       .pollingEvery(Duration.ofSeconds(2))

       .ignoring(NoSuchElementException.class);

driver.findElement(By.xpath("(//div[text()='Marathi'])[3]")).click();

//w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@alt='Chandramukhi (Marathi)']")));

WebElement foo1 = wait.until(new Function<WebDriver, WebElement>() {

     public WebElement apply(WebDriver driver) {

       return driver.findElement(By.xpath("//img[@alt='Chandramukhi (Marathi)']"));

     }

   });

driver.findElement(By.xpath("//img[@alt='Chandramukhi (Marathi)']")).click();

driver.navigate().back();

driver.findElement(By.xpath("(//div[text()='English'])[3]")).click();

//w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@alt='Top Gun: Maverick']")));

WebElement foo2 = wait.until(new Function<WebDriver, WebElement>() {

     public WebElement apply(WebDriver driver) {

       return driver.findElement(By.xpath("//img[@alt='Top Gun: Maverick']"));

     }

   });

driver.findElement(By.xpath("//img[@alt='Top Gun: Maverick']")).click();

}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=TBqovva7EA4&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=18

Explicit Wait in Selenium Webdriver Java | Selenium Explicit Wait | Implicit Wait vs WebDriverWait

                In this post, we will see Explicit Wait in Selenium Webdriver Java | Selenium Explicit Wait | Implicit Wait vs WebDriverWait  


Program Code:

import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;


import java.time.Duration;


public class ExplicitWait {


@SuppressWarnings("deprecation")

public static void main(String[] args) throws InterruptedException 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://in.bookmyshow.com/explore/movies-pune");

driver.manage().window().maximize();

//driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));

WebDriverWait w =new WebDriverWait(driver, Duration.ofSeconds(5));

driver.findElement(By.xpath("(//div[text()='Marathi'])[3]")).click();

w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@alt='Chandramukhi (Marathi)']")));

driver.findElement(By.xpath("//img[@alt='Chandramukhi (Marathi)']")).click();

driver.navigate().back();

driver.findElement(By.xpath("(//div[text()='English'])[3]")).click();

w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@alt='Top Gun: Maverick']")));

driver.findElement(By.xpath("//img[@alt='Top Gun: Maverick']")).click();

}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=f58wLYRoYTc&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=17

Implicit Wait in Selenium Webdriver | Selenium Implicit Wait Java Example | implicitlywait Selenium

                  In this post, we will see Implicit Wait in Selenium Webdriver | Selenium Implicit Wait Java Example | implicitlywait Selenium  


Program Code:

import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;


public class ImplicitWait {


@SuppressWarnings("deprecation")

public static void main(String[] args) throws InterruptedException 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://in.bookmyshow.com/explore/movies-pune");

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));

driver.findElement(By.xpath("(//div[text()='Marathi'])[3]")).click();

driver.findElement(By.xpath("//img[@alt='Chandramukhi (Marathi)']")).click();

driver.navigate().back();

driver.findElement(By.xpath("(//div[text()='English'])[3]")).click();

driver.findElement(By.xpath("//img[@alt='Top Gun: Maverick']")).click();

}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=YBcFp_HnNdI&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=16

How To Achieve Synchronization in Selenium Webdriver | Implicit Wait | Explicit wait | Fluent Wait

               In this post, we will see How To Achieve Synchronization in Selenium Webdriver | Implicit Wait | Explicit wait | Fluent Wait 


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=V6aiS8lFcF8&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=15

How To Debug in Eclipse using Breakpoints | Debugging in Eclipse Java Selenium Code Step by Step

                In this post, we will see How To Debug in Eclipse using Breakpoints | Debugging in Eclipse Java Selenium Code Step by Step 


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=vh4tfrpu77I&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=14

Eclipse Align Code Shortcut | How To Align Code in Eclipse | Eclipse Indentation Shortcut

                   In this post, we will see Eclipse Align Code Shortcut | How To Align Code in Eclipse | Eclipse Indentation Shortcut 


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=xy69mAITNVc&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=13

How To Handle Javascript Alert in Selenium Webdriver using Java | Selenium Javascript Alert Ok

                    In this post, we will see How To Handle Javascript Alert in Selenium Webdriver using Java | Selenium Javascript Alert Ok 


Program Code:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class Alert {


public static void main(String[] args) 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_confirm");

driver.manage().window().maximize();

WebElement w=driver.findElement(By.xpath("//iframe[@id='iframeResult']"));

driver.switchTo().frame(w);

//click try button

driver.findElement(By.xpath("//button[@onclick='myFunction()']")).click();

//driver.switchTo().alert().accept();

driver.switchTo().alert().dismiss();


}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=ezkwV8nSvcg&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=12

Selenium Webdriver Handling iframes | How To Switch Frame in Selenium Webdriver using Java

                  In this post, we will see Selenium Webdriver Handling iframes | How To Switch Frame in Selenium Webdriver using Java 


Program Code:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class Alert {


public static void main(String[] args) 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_confirm");

driver.manage().window().maximize();

WebElement w=driver.findElement(By.xpath("//iframe[@id='iframeResult']"));

driver.switchTo().frame(w);

//click try button

driver.findElement(By.xpath("//button[@onclick='myFunction()']")).click();

//driver.switchTo().alert().accept();

driver.switchTo().alert().dismiss();


}



Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=P10jwhDW1t0&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=12

How To Handle Multiple Radio Button in Selenium Webdriver | Selenium Radio Button Java

                  In this post, we will see How To Handle Multiple Radio Button in Selenium Webdriver | Selenium Radio Button Java 


Program Code:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


import java.util.List;


public class AutoSuggestive {


public static void main(String[] args) throws InterruptedException 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.goibibo.com/");

driver.manage().window().maximize();

//click on From

Thread.sleep(1000);

driver.findElement(By.xpath("(//p[text()='Enter city or airport'])[1]")).click();

//type pune in From

Thread.sleep(1000);

driver.findElement(By.xpath("//input[@type='text']")).sendKeys("pune");

//select pune

Thread.sleep(1000);

driver.findElement(By.xpath("//span[normalize-space()='(PNQ)']")).click();

//type nagpur

Thread.sleep(1000);

driver.findElement(By.xpath("//input[@type='text']")).sendKeys("nagpur");

//select nagpur

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='Nagpur, India']")).click();

//click date Done

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='Done']")).click();

//choose adult Done

Thread.sleep(1000);

driver.findElement(By.xpath("//a[text()='Done']")).click();

//print radio button

Thread.sleep(1000);

List<WebElement> l=driver.findElements(By.xpath("//ul[@class='sc-iqseJM giZLuO']"));

for(WebElement i: l)

{

System.out.println(i.getText());

}

//select student radio button

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='student']")).click();

//selecting adult Done button

Thread.sleep(1000);

driver.findElement(By.xpath("//a[text()='Done']")).click();

//click search button

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='SEARCH FLIGHTS']")).click();


}



Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=knsVEs2G_JM&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=10

How To Handle Auto Suggestion Dropdown in Selenium | Auto Suggest Drop List in Selenium Webdriver

                In this video, we will see How To Handle Auto Suggestion Dropdown in Selenium | Auto Suggest Drop List in Selenium Webdriver 


Program Code

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


import java.util.List;


public class AutoSuggestive {


public static void main(String[] args) throws InterruptedException 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.goibibo.com/");

driver.manage().window().maximize();

//click on From

Thread.sleep(1000);

driver.findElement(By.xpath("(//p[text()='Enter city or airport'])[1]")).click();

//type pune in From

Thread.sleep(1000);

driver.findElement(By.xpath("//input[@type='text']")).sendKeys("pune");

//select pune

Thread.sleep(1000);

driver.findElement(By.xpath("//span[normalize-space()='(PNQ)']")).click();

//type nagpur

Thread.sleep(1000);

driver.findElement(By.xpath("//input[@type='text']")).sendKeys("nagpur");

//select nagpur

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='Nagpur, India']")).click();

//click date Done

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='Done']")).click();

//choose adult Done

Thread.sleep(1000);

driver.findElement(By.xpath("//a[text()='Done']")).click();

//print radio button

Thread.sleep(1000);

List<WebElement> l=driver.findElements(By.xpath("//ul[@class='sc-iqseJM giZLuO']"));

for(WebElement i: l)

{

System.out.println(i.getText());

}

//select student radio button

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='student']")).click();

//selecting adult Done button

Thread.sleep(1000);

driver.findElement(By.xpath("//a[text()='Done']")).click();

//click search button

Thread.sleep(1000);

driver.findElement(By.xpath("//span[text()='SEARCH FLIGHTS']")).click();


}



Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=hkRL6eFMlWA&list=PLhbrpS8rYbc0vBS6Z8SC7OR-zknTBiBHW&index=9

Selenium Checkbox Select | How To Handle Checkbox in Selenium Webdriver Java | How To Print List

                     In this post, we will see Selenium Checkbox Select | How To Handle Checkbox in Selenium Webdriver Java | How To Print List 


Program Code:

import java.util.*;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;




public class checkbox {


public static void main(String[] args) throws InterruptedException 

{

System.setProperty("webdriver.gecko.driver", "C:\\selenium\\geckodriver-v0.31.0-win64\\geckodriver.exe");

WebDriver driver=new FirefoxDriver();

driver.get("https://www.irctc.co.in/nget/train-search");

Thread.sleep(1000);

driver.manage().window().maximize();

Thread.sleep(1000);

driver.findElement(By.xpath("//button[normalize-space()='OK']")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//input[@class='ng-tns-c58-8 ui-inputtext ui-widget ui-state-default ui-corner-all ui-autocomplete-input ng-star-inserted']")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//span[contains(text(),'PUNE JN - PUNE')]")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("(//input[@class='ng-tns-c58-9 ui-inputtext ui-widget ui-state-default ui-corner-all ui-autocomplete-input ng-star-inserted'])[1]")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//span[normalize-space()='NAGPUR - NGP']")).click();

Thread.sleep(1000);

//driver.findElement(By.xpath("//div[@class='ng-tns-c66-12 ui-dropdown ui-widget ui-state-default ui-corner-all']")).click();

//Thread.sleep(1000);

//driver.findElement(By.xpath("//span[normalize-space()='TATKAL']")).click();

//Thread.sleep(1000);

List<WebElement> l=driver.findElements(By.xpath("//div[@class='col-xs-12 remove-padding']//div[@class='col-xs-12 remove-padding']"));

int a=5;

display();

for(WebElement i:l)

{

System.out.println(i.getText());

}

Thread.sleep(2000);

driver.findElement(By.xpath("//label[@for='concessionBooking']")).click();

Thread.sleep(2000);

driver.findElement(By.xpath("//span[@class='ui-button-text ui-clickable']")).click();

driver.findElement(By.xpath("//button[@type='submit']")).click();

//driver.switchTo().alert().accept();


}

static void display()

{

System.out.println("Showing Checkboxes");

}


}


         Watch following video:

How To Handle Static Dropdown in Selenium | Static Dropdown in Selenium Webdriver using Java

                     In this post, we will see How To Handle Static Dropdown in Selenium | Static Dropdown in Selenium Webdriver using Java 


Program Code:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class staticdropdown {


public static void main(String[] args) throws InterruptedException 

{

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.irctc.co.in/nget/train-search");

Thread.sleep(1000);

driver.manage().window().maximize();

Thread.sleep(1000);

driver.findElement(By.xpath("//button[normalize-space()='OK']")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//input[@class='ng-tns-c58-8 ui-inputtext ui-widget ui-state-default ui-corner-all ui-autocomplete-input ng-star-inserted']")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//span[contains(text(),'PUNE JN - PUNE')]")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("(//input[@class='ng-tns-c58-9 ui-inputtext ui-widget ui-state-default ui-corner-all ui-autocomplete-input ng-star-inserted'])[1]")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//span[normalize-space()='NAGPUR - NGP']")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//div[@class='ng-tns-c66-12 ui-dropdown ui-widget ui-state-default ui-corner-all']")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//span[normalize-space()='TATKAL']")).click();

Thread.sleep(1000);

driver.findElement(By.xpath("//button[@type='submit']")).click();

}


}


 Watch following video: