Sunday 24 June 2018

Spinner To handle in Selenium











Firstname Lastname Age Select
Jill Smith 50
Eve Jackson 94
John Doe 80

Handling Spinner in Selenium

Handling Spinner In Selenium:

       To handle Spinner in selenium we have to use Synchronization concept with the help of wait.
It is always best to use Explicit Wait  on each control. so we have been  using Explicit Wait in our below example.

We are handling Spinner from  Spinner Link  this link. Click on it.

Basically above link contains two buttons-
1- Show Spinner
2- Hide Spinner

Show Spinner: When we click "Show Spinner" button then spinner is moving with 5-second timeout once 5-Second elapsed data will be loaded in tabular format.

Hide Spinner: When we click on "Hide Spinner" button It will hide the Spinner as well as tabular data (if tabular data is present/already loaded on page)

Intention of having such scenario/example is correlating with real time scenario- where when user click on any button then data is fetching from database in mean time spinner is running on page and  block the page activity once the data is ready spinner will disappear from screen.


Explicit Wait:
  1. WebdriverWait
  2. FluentWait
In below example we have used fluent wait with Function which is parameter to until function.
In example we have passed Webdriver object and By class object which is the locator path to spinner to function - waitTillSpinnerDisable(WebDriver driver, By by)

apply(): We have override apply method which will return either true or false. In example  it will return TRUE  in case of spinner is disappear (i.e. style.display="none") else it will return FALSE in case of timeout or style.display="block".

Once the Spinner is disappear it will load the data in tabular format and we have to parse the table where we need to select check on the basis of if  Name & Surname gets matched with tabular data where we passed Name & Surname at  execution time.


Execution Steps:
  1. Load the page
  2. Click on Show Spinner button
  3. Pass the driver object and locator for Spinner to waitTillSpinnerDisappear method
  4. Check the method return type if above method waitTillSpinnerDisappear return true then
  5. Parse the table with condition Name & Surname gets matched if match then select respective check box.
Download:

Download Spinner.html file form below link :- 


or 

Refer to page- 




Java Code:


Sunday 17 June 2018

Handling Dynamic Web Tables Using Selenium


Handling Dynamic Web Tables Using Selenium by using XPATH

     In below example we have consider Application Under Test from url as- https://www.redmine.org/issues . 
Where this url/application contains issues reported by users etc.. All the reported issues are in 
tabular format. In below example we have used xpath with multiple condition in a single xpath.
Also we have passed java variable as a argument to xpath at runtime.
        Here, we have to pass issueId and status as a argument below code will check issueId and respective 
status code is matched or not with table data if not it will click on next page and searched 
the given condition with table data it will search until it will find at least one of the record. 
Once the record found then execution will stop.


Screenshot of the Page:


Java Code:

package seleniumCode;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class WebTable 
{
 public static void main(String[] args) 
  {
     WebDriver driver = null;  
     List<WebElement> listWebElement = null;
     boolean flag = false;
  
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("https://www.redmine.org/issues");
    
    String issueId = "28232";
    String status = "New";
  
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    do
     {   
 listWebElement = driver.findElements(By.xpath("//table[@class='list issues']
          //tr//a[text()='"+issueId+"']//ancestor::td//following-sibling::
         td[text()='"+status+"']//preceding-sibling::td/input"));
   
 for (WebElement element : listWebElement) 
 {
  System.out.println(element.getAttribute("value"));
  element.click();
  flag = true;
  break;
 }
  
 if(flag==true)
   break;
 if(flag == false || listWebElement.size()==0)
  {
    //Page Down
    Actions ac = new Actions(driver);
    ac.moveToElement(driver.findElement(By.cssSelector("a.atom"))).build().perform();
    try 
             {
  Thread.sleep(2000);
       } 
           catch (InterruptedException e) 
            {
       // TODO Auto-generated catch block
  e.printStackTrace();
     }    
    
     driver.findElements(By.cssSelector("a.next")).get(0).click();
 }
  
      }while(driver.findElements(By.cssSelector("a.next")).size()>0 || flag==false);
   } 
 
}




References:  https://www.redmine.org/issues

See Also: