NexGenration

Selenium LEX 3

Dec 4th, 2021
838
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.test;
  2.  
  3. import org.openqa.selenium.interactions.Actions;
  4. import org.openqa.selenium.support.ui.ExpectedConditions;
  5. import org.openqa.selenium.support.ui.WebDriverWait;
  6.  
  7. public class Demo17_DealingWithAjaxControl {
  8.  
  9.     WebDriver driver;
  10.     String url = "http://demo/Login.aspx";     // This URL and scenario is only for reference.
  11.  
  12.     @Before
  13.     public void setUp() {
  14.         //Set the key/value property according to the browser you are using.
  15.         //Open browser instance
  16.         //Open the AUT     
  17.         //Declare an implicit wait which is bounded to WebDriver instance
  18.     }
  19.  
  20.     @Test
  21.     public void test() throws InterruptedException {
  22.         //Login into the application
  23.        
  24.         //Employee link
  25.         WebElement linkEmployee = driver.findElement(By.xpath("html/body/form/div[6]/div/div[1]/div[1]/ul/li[4]/a"));
  26.        
  27.         //Details links --- After hovering Employee link
  28.         WebElement linkDetails = driver.findElement(By.xpath("html/body/form/div[6]/div/div[1]/div[1]/ul/li[4]/ul/li[1]/a"));
  29.        
  30.         //Use the action class to
  31.         Actions action = new Actions(driver);
  32.         action.moveToElement(linkEmployee).moveToElement(linkDetails).click().build().perform();
  33.        
  34.         //Explicit wait with a maximum of 20seconds
  35.         WebDriverWait wait = new WebDriverWait(driver, 20);
  36.        
  37.         //Wait until the table gets displayed
  38.         wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin"))));
  39.        
  40.         //click on the edit button in the first row
  41.         driver.findElement(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin_btnEdit_0")).click();
  42.        
  43.         //wait until the row gets converted into a textbox             
  44.                 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin_QualificationDescription_0")));
  45.        
  46.         //clear the data corresponding to Qualification Description and input some value
  47.         driver.findElement(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin_QualificationDescription_0")).clear();
  48.         driver.findElement(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin_QualificationDescription_0")).sendKeys("MCA");
  49.        
  50.         //clear the data corresponding to Year of Qualification and input some value
  51.         driver.findElement(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin_YearOfQualification_0")).clear();
  52.         driver.findElement(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin_YearOfQualification_0")).sendKeys("1993");
  53.        
  54.         //Click on the update button
  55.         driver.findElement(By.id("cphMainContent_tcEmployeeDetails_tpUpdateQualifications_grdQualificationForAdmin_btnUpdateEdition_0")).click();
  56.        
  57.         //wait for the succes message to get displayed, fetch the message and print it in the console
  58.         wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("html/body/form/div[6]/div/div[2]/div[2]/div/div/div[2]/div[3]/div[2]/div/span")));
  59.         String statusMessage = driver.findElement(By.xpath("html/body/form/div[6]/div/div[2]/div[2]/div/div/div[2]/div[3]/div[2]/div/span")).getText();
  60.        
  61.         System.out.println("Status Message: " + statusMessage);
  62.        
  63.         //Logout from the applicaiton
  64.         driver.findElement(By.xpath("html/body/form/div[4]/div/div[2]/div[1]/a")).click();
  65.     }
  66.  
  67.     @After
  68.     public void tearDown() {
  69.         //Close the browser
  70.     }
  71. }
  72.  
RAW Paste Data