├── Azure.java ├── BBRiceDhal.java ├── CarWale.java ├── Honda.java ├── HpPavilion.java ├── HpPaviliondispop.java ├── JustDial.java ├── MakeMytrip.java ├── Myntra.java ├── Nykaa.java ├── Pepperfry.java ├── README.md ├── Shiksha.java ├── SnapDeal.java ├── Take Notes.docx ├── TestAzure.java ├── TestHonda.java ├── TestNaukri.java ├── Zalando.java ├── airbnb.java └── ajio.java /Azure.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.io.File; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.JavascriptExecutor; 7 | import org.openqa.selenium.Keys; 8 | import org.openqa.selenium.UnexpectedAlertBehaviour; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.remote.CapabilityType; 14 | import org.openqa.selenium.remote.DesiredCapabilities; 15 | import org.openqa.selenium.support.ui.ExpectedConditions; 16 | import org.openqa.selenium.support.ui.Select; 17 | import org.openqa.selenium.support.ui.WebDriverWait; 18 | 19 | public class Azure { 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | // TODO Auto-generated method stub 23 | // 1) Go to https://azure.microsoft.com/en-in/ 24 | System.setProperty("webdriver.chrome.silentOutput", "true"); 25 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 26 | // disable the notifications 27 | ChromeOptions options = new ChromeOptions(); 28 | options.addArguments("--disable-notifications"); 29 | 30 | DesiredCapabilities cap = new DesiredCapabilities(); 31 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 32 | options.merge(cap); 33 | // Launching Chrome Browser 34 | ChromeDriver driver = new ChromeDriver(options); 35 | // To Load the url 36 | driver.get("https://azure.microsoft.com/en-in/"); 37 | // To maximize the browser 38 | driver.manage().window().maximize(); 39 | // implicitly wait 40 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 41 | WebDriverWait wait = new WebDriverWait(driver, 10); 42 | JavascriptExecutor js = (JavascriptExecutor) driver; 43 | Actions action=new Actions(driver); 44 | 45 | // 2) Click on Pricing 46 | driver.findElementById("navigation-pricing").click(); 47 | Thread.sleep(1000); 48 | // 3) Click on Pricing Calculator 49 | driver.findElementByLinkText("Pricing calculator").click(); 50 | Thread.sleep(3000); 51 | // 4) Click on Containers 52 | WebElement containers=driver.findElementByXPath("//button[@data-event-property='containers']"); 53 | wait.until(ExpectedConditions.elementToBeClickable(containers)); 54 | 55 | js.executeScript("arguments[0].click()",containers); 56 | 57 | 58 | // 5) Select Container Instances 59 | driver.findElementByXPath("(//span[text()='Container Instances'])[3]").click(); 60 | // 6) Click on Container Instance Added View 61 | driver.findElementById("new-module-loc").click(); 62 | // 7) Select Region as "South India" 63 | WebElement region=driver.findElementByXPath("(//select[@name='region'])[1]"); 64 | Select dropdown=new Select(region); 65 | dropdown.selectByVisibleText("South India"); 66 | // 8) Set the Duration as 180000 seconds 67 | WebElement duration=driver.findElementByXPath("(//input[@aria-label='Seconds'])[1]"); 68 | duration.click(); 69 | duration.sendKeys(Keys.HOME, Keys.chord(Keys.SHIFT, Keys.END),"180000"); 70 | //keys.chord(Keys.CONTROL,"a"),"seonds value" 71 | 72 | 73 | // //input[@aria-label='Seconds'] 74 | 75 | // 9) Select the Memory as 4GB 76 | WebElement memory=driver.findElementByXPath("(//select[@class='select'])[3]"); 77 | Select memlist=new Select(memory); 78 | memlist.selectByVisibleText("4 GB"); 79 | // 10) Enable SHOW DEV/TEST PRICING 80 | driver.findElementById("devtest-toggler").click(); 81 | // 11) Select Indian Rupee as currency 82 | WebElement currency=driver.findElementByXPath("//select[@class='select currency-dropdown']"); 83 | Select currencylist=new Select(currency); 84 | currencylist.selectByVisibleText("Indian Rupee (₹)"); 85 | 86 | // 12) Print the Estimated monthly price 87 | String estmthprice=driver.findElementByXPath("(//div[@class='column large-3 text-right total']//span[@class='numeric'])[2]").getText(); 88 | System.out.println(estmthprice); 89 | // 13) Click on Export to download the estimate as excel 90 | driver.findElementByXPath("//button[text()='Export']").click(); 91 | // 14) Verify the downloded file in the local folder 92 | File f = new File("Macintosh HD/Users/kumanananitha/Downloads/ExportedEstimate(*).xlsx"); 93 | if(f.exists() ) { 94 | // do something 95 | System.out.println("File exists"); 96 | } 97 | else { System.out.println("file do not exist"); } 98 | // 15) Navigate to Example Scenarios and Select CI/CD for Containers 99 | Thread.sleep(2000); 100 | //WebElement example_scenary=driver.findElementByLinkText("Example Scenarios"); 101 | WebElement example_scenary=driver.findElementByXPath("//a[@href='solution-architectures-picker-panel']"); 102 | 103 | wait.until(ExpectedConditions.elementToBeClickable(example_scenary)); 104 | //example_scenary.click(); 105 | js.executeScript("arguments[0].click()",example_scenary); 106 | Thread.sleep(1000); 107 | WebElement CICDcontain=driver.findElementByXPath("//span[text()='CI/CD for Containers']"); 108 | wait.until(ExpectedConditions.elementToBeClickable(CICDcontain)); 109 | //CICDcontain.click(); 110 | js.executeScript("arguments[0].click()",CICDcontain); 111 | 112 | // 16) Click Add to Estimate 113 | WebElement addtoest=driver.findElementByXPath("//button[text()='Add to estimate']"); 114 | wait.until(ExpectedConditions.elementToBeClickable(addtoest)); 115 | //addtoest.click(); 116 | js.executeScript("arguments[0].click()",addtoest); 117 | 118 | Thread.sleep(3000); 119 | // 17) Change the Currency as Indian Rupee 120 | WebElement currlist=driver.findElementByXPath("//select[@class='select currency-dropdown']"); 121 | Select clist=new Select(currlist); 122 | clist.selectByVisibleText("Indian Rupee (₹)"); 123 | // 18) Enable SHOW DEV/TEST PRICING 124 | driver.findElementById("devtest-toggler").click(); 125 | Thread.sleep(500); 126 | // 19) Export the Estimate 127 | driver.findElementByXPath("//button[text()='Export']").click(); 128 | // 20) Verify the downloded file in the local folder 129 | File f1 = new File("Macintosh HD/Users/kumanananitha/Downloads/ExportedEstimate(*).xlsx"); 130 | if(f1.exists() ) { 131 | // do something 132 | System.out.println("File exists"); 133 | } 134 | else { System.out.println("file do not exist"); } 135 | 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /BBRiceDhal.java: -------------------------------------------------------------------------------- 1 | package SeleniumCoding; 2 | 3 | 4 | import java.util.List; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.openqa.selenium.Keys; 8 | import org.openqa.selenium.UnexpectedAlertBehaviour; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.remote.CapabilityType; 14 | import org.openqa.selenium.remote.DesiredCapabilities; 15 | import org.openqa.selenium.support.ui.Select; 16 | 17 | public class BBRiceDhal { 18 | 19 | public static void main(String args[]) throws InterruptedException { 20 | System.setProperty("webdriver.chrome.silentOutput", "true"); 21 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 22 | // disable the notifications 23 | ChromeOptions options = new ChromeOptions(); 24 | options.addArguments("--disable-notifications"); 25 | 26 | DesiredCapabilities cap = new DesiredCapabilities(); 27 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 28 | options.merge(cap); 29 | // Launching Chrome Browser 30 | ChromeDriver driver = new ChromeDriver(options); 31 | // To Load the url 32 | driver.get("https://www.bigbasket.com/"); 33 | // To maximize the browser 34 | driver.manage().window().maximize(); 35 | // implicitly wait 36 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 37 | driver.findElementByXPath("//span[@class='close-btn']").click(); 38 | Thread.sleep(1000); 39 | // mouse over on Shop by Category 40 | WebElement eleCategory = driver.findElementByXPath("//a[text()=' Shop by Category ']"); 41 | Actions builder = new Actions(driver); 42 | builder.moveToElement(eleCategory).perform(); 43 | Thread.sleep(1000); 44 | 45 | // Go to FOODGRAINS, OIL & MASALA --> RICE & RICE PRODUCTS 46 | WebElement elefood = driver.findElementByXPath("(//a[text()='Foodgrains, Oil & Masala'])[2]"); 47 | Actions builder1 = new Actions(driver); 48 | builder1.moveToElement(elefood).perform(); 49 | Thread.sleep(3000); 50 | WebElement elerice = driver.findElementByXPath("(//a[text()='Rice & Rice Products'])[2]"); 51 | Actions builder2 = new Actions(driver); 52 | builder2.moveToElement(elerice).perform(); 53 | Thread.sleep(3000); 54 | 55 | // Click on Boiled & Steam Rice 56 | driver.findElementByXPath("(//a[text()='Boiled & Steam Rice'])[2]").click(); 57 | Thread.sleep(6000); 58 | // Choose the Brand as bb Royal 59 | driver.findElementByXPath("(//span[text()='bb Royal'])[1]").click(); 60 | Thread.sleep(5000); 61 | // Go to Ponni Boiled Rice - Super Premium and select 5kg bag from Dropdown 62 | driver.findElementByXPath("(//a[text()='Ponni Boiled Rice - Super Premium']/following::div[@class='btn-group btn-input clearfix ng-scope'])[1]") 63 | .click(); 64 | driver.findElementByXPath("(//a[text()='Ponni Boiled Rice - Super Premium']/following::span[contains(text(),'5 kg')])[1]") 65 | .click(); 66 | 67 | // print the price of Rice 68 | String ricePrice = driver 69 | .findElementByXPath("(//a[text()='Ponni Boiled Rice - Super Premium']/following::span[@class='discnt-price'])[1]") 70 | .getText(); 71 | System.out.println("The price of the rice is " + ricePrice); 72 | 73 | // Click Add button 74 | driver.findElementByXPath("(//a[text()='Ponni Boiled Rice - Super Premium']/following::button[@qa='add'])[1]") 75 | .click(); 76 | Thread.sleep(2000); 77 | // driver.findElementByXPath("(//a[text()='Continue'])[1]").click(); 78 | // Thread.sleep(4000); 79 | 80 | // Verify the success message displayed 81 | String addMsg = driver.findElementByXPath("//div[@class='toast-title']").getText(); 82 | if (addMsg.equalsIgnoreCase("Successfully added Ponni Boiled Rice - Super Premium 5 kg to the basket")) { 83 | System.out.println("The meassage after adding rice into cart is " + addMsg); 84 | Thread.sleep(3000); 85 | } else { 86 | System.out.println("Wrong message displayed" + addMsg); 87 | } 88 | // Type Dal in Search field and enter 89 | driver.findElementByXPath("//input[@id='input']").sendKeys("DAL", Keys.ENTER); 90 | Thread.sleep(3000); 91 | // Go to Toor/Arhar Dal and select 2kg & set Qty 2 92 | driver.findElementByXPath( 93 | "(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::div[@class='btn-group btn-input clearfix ng-scope'])[1]") 94 | .click(); 95 | driver.findElementByXPath( 96 | "(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::span[contains(text(),'2 kg')])[1]").click(); 97 | WebElement quantity = driver 98 | .findElementByXPath("(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::input)[1]"); 99 | quantity.clear(); 100 | quantity.sendKeys("2"); 101 | 102 | // Print the price of Dal 103 | String dalPrice = driver 104 | .findElementByXPath( 105 | "(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::span[@class='discnt-price'])[1]") 106 | .getText(); 107 | System.out.println("The Price of Dal is " + dalPrice); 108 | // Click Add button 109 | driver.findElementByXPath("(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::button[@qa='add'])[1]") 110 | .click(); 111 | Thread.sleep(2000); 112 | 113 | String addMsgDal = driver.findElementByXPath("//div[@class='toast-title']").getText(); 114 | if (addMsgDal.equalsIgnoreCase("Successfully added Toor/Arhar Dal/Thuvaram Paruppu 2 kg to the basket")) { 115 | System.out.println("The meassage after adding dal into cart is " + addMsgDal); 116 | } else { 117 | System.out.println("Wrong message displayed" + addMsgDal); 118 | } 119 | driver.findElementByXPath("//button[@class='toast-close-button']").click(); 120 | // Mouse hover on My Basket 121 | WebElement elecart = driver.findElementByXPath("//span[@class='basket-content']"); 122 | Actions builder3 = new Actions(driver); 123 | builder3.moveToElement(elecart).perform(); 124 | Thread.sleep(3000); 125 | 126 | // Validate the Sub Total displayed for the selected items 127 | String subTotal = driver.findElementByXPath("//span[@qa='subTotalMB']").getText(); 128 | // System.out.println(subTotal); 129 | // String total = subTotal.replaceAll("\\D", ""); 130 | double dblSTotal = Double.parseDouble(subTotal); 131 | System.out.println("Subtotal before reducing the Quantity of dhal is " + dblSTotal); 132 | System.out.println(" "); 133 | 134 | String rPrice = driver.findElementByXPath("(//span[@qa='priceMB'])[1]").getText(); 135 | String rQuantity = driver.findElementByXPath("(//div[@qa='pcsMB'])[1]").getText(); 136 | String riceQuantity = rQuantity.substring(0, 1); 137 | // System.out.println(riceQuantity); 138 | double totalRiceQuantity = Double.parseDouble(riceQuantity); 139 | double priceOfRice = Double.parseDouble(rPrice); 140 | double riceTotalPrice = totalRiceQuantity * priceOfRice; 141 | System.out.println("Total Price of Rice is " + riceTotalPrice); 142 | System.out.println(" "); 143 | 144 | String dPrice = driver.findElementByXPath("(//span[@qa='priceMB'])[2]").getText(); 145 | String dQuantity = driver.findElementByXPath("(//div[@qa='pcsMB'])[2]").getText(); 146 | String dalQuantity = dQuantity.substring(0, 1); 147 | // System.out.println(dalQuantity); 148 | double totalDalQuantity = Double.parseDouble(dalQuantity); 149 | double priceOfDal = Double.parseDouble(dPrice); 150 | double dalTotalPrice = totalDalQuantity * priceOfDal; 151 | System.out.println("Total price of dal before reducing the Quantity is " + dalTotalPrice); 152 | System.out.println(" "); 153 | 154 | double overallTotal = riceTotalPrice + dalTotalPrice; 155 | if (dblSTotal == overallTotal) { 156 | System.out.println( 157 | "The SubTotal is validated with the calculated amount for the products before reducing the Quantity"); 158 | } else { 159 | System.out.println("The subtotal is getting mismatched"); 160 | } 161 | System.out.println(" "); 162 | System.out.println(" "); 163 | 164 | // Reduce the Quantity of Dal as 1 165 | driver.findElementByXPath("(//button[@qa='decQtyMB'])[2]").click(); 166 | Thread.sleep(1000); 167 | // Validate the Sub Total for the current items 168 | String dPrice1 = driver.findElementByXPath("(//span[@qa='priceMB'])[2]").getText(); 169 | String dQuantity1 = driver.findElementByXPath("(//div[@qa='pcsMB'])[2]").getText(); 170 | String dalQuantity1 = dQuantity1.substring(0, 1); 171 | // System.out.println(dalQuantity1); 172 | double totalDalQuantity1 = Double.parseDouble(dalQuantity1); 173 | double priceOfDal1 = Double.parseDouble(dPrice1); 174 | double dalTotalPrice1 = totalDalQuantity1 * priceOfDal1; 175 | System.out.println("Total price of dal after reducing the quantity is " + dalTotalPrice1); 176 | System.out.println(" "); 177 | 178 | String subTotal1 = driver.findElementByXPath("//span[@qa='subTotalMB']").getText(); 179 | double dblSTotal1 = Double.parseDouble(subTotal1); 180 | System.out.println("Subtotal after reducing the quantity of dal is " + dblSTotal1); 181 | System.out.println(" "); 182 | 183 | double overallTotal1 = riceTotalPrice + dalTotalPrice1; 184 | 185 | if (dblSTotal1 == overallTotal1) { 186 | System.out.println( 187 | "The SubTotal is validated with the calculated amount for the products after reducing the quantity of dal"); 188 | } else { 189 | System.out.println("The subtotal is getting mismatched"); 190 | } 191 | 192 | // Close the Browser 193 | driver.close(); 194 | } 195 | } 196 | 197 | 198 | -------------------------------------------------------------------------------- /CarWale.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.LinkedHashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Map.Entry; 9 | import java.util.Set; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import org.openqa.selenium.JavascriptExecutor; 13 | import org.openqa.selenium.Keys; 14 | import org.openqa.selenium.UnexpectedAlertBehaviour; 15 | import org.openqa.selenium.WebDriver.Window; 16 | import org.openqa.selenium.WebElement; 17 | import org.openqa.selenium.chrome.ChromeDriver; 18 | import org.openqa.selenium.chrome.ChromeOptions; 19 | import org.openqa.selenium.remote.CapabilityType; 20 | import org.openqa.selenium.remote.DesiredCapabilities; 21 | import org.openqa.selenium.support.ui.ExpectedConditions; 22 | import org.openqa.selenium.support.ui.Select; 23 | import org.openqa.selenium.support.ui.WebDriverWait; 24 | 25 | public class CarWale { 26 | 27 | public static void main(String[] args) throws InterruptedException { 28 | // TODO Auto-generated method stub 29 | // 1) Go to https://www.carwale.com/ 30 | System.setProperty("webdriver.chrome.silentOutput", "true"); 31 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 32 | // disable the notifications 33 | ChromeOptions options = new ChromeOptions(); 34 | options.addArguments("--disable-notifications"); 35 | DesiredCapabilities cap = new DesiredCapabilities(); 36 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 37 | options.merge(cap); 38 | // Launching Chrome Browser 39 | ChromeDriver driver = new ChromeDriver(options); 40 | // To Load the url 41 | driver.get("https://www.carwale.com/"); 42 | // To maximize the browser 43 | driver.manage().window().maximize(); 44 | // implicitly wait 45 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 46 | WebDriverWait wait = new WebDriverWait(driver, 30); 47 | JavascriptExecutor js = (JavascriptExecutor) driver; 48 | 49 | // 2) Click on Used 50 | driver.findElementByXPath("//li[@data-tabs='usedCars']").click(); 51 | // 3) Select the City as Chennai 52 | driver.findElementById("usedCarsList").sendKeys("Chennai",Keys.ENTER); 53 | Thread.sleep(500); 54 | // 4) Select budget min (8L) and max(12L) and Click Search 55 | driver.findElementById("budgetBtn").click(); 56 | driver.findElementById("minInput").sendKeys("8",Keys.ENTER); 57 | driver.findElementById("maxInput").sendKeys("12",Keys.ENTER); 58 | driver.findElementById("btnFindCar").click(); 59 | Thread.sleep(1000); 60 | driver.findElementByXPath("//input[@id='placesQuery']").sendKeys("Chennai,Tamil Nadu",Keys.ENTER); 61 | driver.findElementByXPath("//span[@id='closeLocIcon']").click(); 62 | // 5) Select Cars with Photos under Only Show Cars With 63 | Thread.sleep(1000); 64 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Cars with Photos']"))); 65 | driver.findElementByXPath("//span[text()='Cars with Photos']").click(); 66 | // 6) Select Manufacturer as "Hyundai" --> Creta 67 | Thread.sleep(500); 68 | WebElement Hyundai=driver.findElementByXPath("(//li[@data-manufacture-en='Hyundai']/span)[1]"); 69 | js.executeScript("arguments[0].click()",Hyundai); 70 | //wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//li[@data-manufacture-en='Hyundai']/span)[1]"))); 71 | //driver.findElementByXPath("(//li[@data-manufacture-en='Hyundai']/span)[1]").click(); 72 | WebElement Creta=driver.findElementByXPath("//span[text()='Creta']"); 73 | js.executeScript("arguments[0].click()",Creta); 74 | //driver.findElementByXPath("//span[text()='Creta']").click(); 75 | // 7) Select Fuel Type as Petrol 76 | WebElement fueltype=driver.findElementByXPath("//h3[text()[normalize-space()='Fuel Type']]"); 77 | js.executeScript("arguments[0].click()",fueltype); 78 | //driver.findElementByXPath("//h3[text()[normalize-space()='Fuel Type']]").click(); 79 | WebElement petrol=driver.findElementByXPath("//span[text()='Petrol']"); 80 | js.executeScript("arguments[0].click()",petrol); 81 | //driver.findElementByXPath("//span[text()='Petrol']").click(); 82 | // 8) Select Best Match as "KM: Low to High" 83 | WebElement match= driver.findElementById("sort"); 84 | Select select=new Select(match); 85 | select.selectByValue("2"); 86 | 87 | // 9) Validate the Cars are listed with KMs Low to High 88 | //LInked Hash Map to which all the data will be stored 89 | //(//span[@class='slkms vehicle-data__item'])[2] 90 | List noofcars=driver.findElementsByXPath("//span[contains(@class,'slkms vehicle')]"); 91 | Map kmmap = new LinkedHashMap(); 92 | // List carname=driver.findElementsByXPath("(//span[@data-carname-id='carname'])["+i+"]"); 93 | //list which is used to store the kms got from the list 94 | List vehicleKM=new ArrayList(); 95 | //List distance=driver.findElementsByXPath("(//span[@class='slkms vehicle-data__item'])["+i+"]"); 96 | for(int i=0;i< noofcars.size();i++) 97 | { 98 | String rawKM=noofcars.get(i).getText(); 99 | int intKM = Integer.parseInt(rawKM.replaceAll("\\D", "")); 100 | vehicleKM.add(intKM); 101 | kmmap.put(intKM,rawKM ); 102 | } 103 | //Create copy of the Integer List, sort and compare two lists 104 | 105 | List sortedKM=new ArrayList (vehicleKM); 106 | Collections.sort(sortedKM); 107 | if(vehicleKM.equals(sortedKM)) 108 | System.out.println("Huyandi car kms are sorted"); 109 | else System.out.println("Huyandi car kms are not sorted"); 110 | 111 | // 10) Add the least KM ran car to Wishlist 112 | Integer lessKM=sortedKM.get(0); 113 | String lessKMcar=""; 114 | for(Entry eachEntry:kmmap.entrySet()) 115 | { 116 | if(eachEntry.getKey().equals(lessKM)) 117 | { lessKMcar=eachEntry.getValue(); } 118 | 119 | } 120 | System.out.println("Less km utilised by Creta Car"+lessKMcar); 121 | Thread.sleep(500); 122 | WebElement lesskmwishlist=driver.findElementByXPath("//span[text()='"+lessKMcar+"']/ancestor::div[@class='card-detail-block']/preceding-sibling::div//span[contains(@class,'shortlist-icon')]"); 123 | //span[text()='8,000 km']/ancestor::div[@class='card-detail-block']/preceding-sibling::div//span[contains(@class,'shortlist-icon')] 124 | js.executeScript("arguments[0].click();",lesskmwishlist ); 125 | // 11) Go to Wishlist and Click on More Details 126 | Thread.sleep(500); 127 | driver.findElementByXPath("//li[@data-action='ShortList&CompareWindow_Click']").click(); 128 | Thread.sleep(500); 129 | driver.findElementByLinkText("More details »").click(); 130 | // 12) Print all the details under Overview in the same way as displayed in application 131 | Set winset=driver.getWindowHandles(); 132 | List winlist=new ArrayList (winset); 133 | driver.switchTo().window(winlist.get(1)); 134 | List cardesc=driver.findElementsByXPath("//div[@id='overview']//div[@class='equal-width text-light-grey']"); 135 | List carspec=driver.findElementsByXPath("//div[@id='overview']//div[@class='equal-width dark-text']"); 136 | Map cardetails= new LinkedHashMap (); 137 | System.out.println("description size"+cardesc.size()); 138 | System.out.println("specification size"+carspec.size()); 139 | for(int i=0;i eachEntry:cardetails.entrySet()) 145 | { 146 | System.out.println(eachEntry.getKey()+"---->"+eachEntry.getValue()); 147 | } 148 | //div[@class='equal-width dark-text'] 149 | 150 | // 13) Close the browser. 151 | driver.quit(); 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /Honda.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | import java.util.Map.Entry; 7 | import java.util.Set; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import org.openqa.selenium.JavascriptExecutor; 11 | import org.openqa.selenium.UnexpectedAlertBehaviour; 12 | import org.openqa.selenium.chrome.ChromeDriver; 13 | import org.openqa.selenium.chrome.ChromeOptions; 14 | import org.openqa.selenium.remote.CapabilityType; 15 | import org.openqa.selenium.remote.DesiredCapabilities; 16 | import org.openqa.selenium.support.ui.Select; 17 | import org.openqa.selenium.support.ui.WebDriverWait; 18 | 19 | public class Honda { 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | // TODO Auto-generated method stub 23 | 24 | // 1) Go to https://www.honda2wheelersindia.com/ 25 | System.setProperty("webdriver.chrome.silentOutput", "true"); 26 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 27 | // disable the notifications 28 | ChromeOptions options = new ChromeOptions(); 29 | options.addArguments("--disable-notifications"); 30 | 31 | DesiredCapabilities cap = new DesiredCapabilities(); 32 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 33 | options.merge(cap); 34 | // Launching Chrome Browser 35 | ChromeDriver driver = new ChromeDriver(options); 36 | // To Load the url 37 | driver.get("https://www.honda2wheelersindia.com/"); 38 | // To maximize the browser 39 | driver.manage().window().maximize(); 40 | // implicitly wait 41 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 42 | driver.findElementByXPath("//button[@class='close']").click(); 43 | WebDriverWait wait = new WebDriverWait(driver, 30); 44 | JavascriptExecutor js = (JavascriptExecutor) driver; 45 | //js.executeScript("window.scrollBy(0, 250)"); 46 | // 2) Click on scooters and click dio 47 | driver.findElementByXPath("//a[@id='link_Scooter']").click(); 48 | Thread.sleep(2000); 49 | driver.findElementByXPath("//img[@src='/assets/images/thumb/dioBS6-icon.png']").click(); 50 | // 3) Click on Specifications and mouseover on ENGINE 51 | driver.findElementByLinkText("Specifications").click(); 52 | driver.findElementByLinkText("ENGINE").click(); 53 | // 4) Get Displacement value 54 | Thread.sleep(2000); 55 | String dispval_Dio=driver.findElementByXPath("//span[text()='109.51cc']").getText(); 56 | String dispval=dispval_Dio.replaceAll("cc",""); 57 | System.out.println(dispval); 58 | double dio=Double.parseDouble(dispval); 59 | System.out.println(dio); 60 | // 5) Go to Scooters and click Activa 125 61 | driver.findElementByXPath("//a[@id='link_Scooter']").click(); 62 | driver.findElementByXPath("//img[@src='/assets/images/thumb/activa-125new-icon.png']").click(); 63 | // 6) Click on Specifications and mouseover on ENGINE 64 | driver.findElementByLinkText("Specifications").click(); 65 | driver.findElementByLinkText("ENGINE").click(); 66 | // 7) Get Displacement value 67 | String dispval_Act125=driver.findElementByXPath("//span[text()='Displacement']/following-sibling::span").getText(); 68 | dispval_Act125=dispval_Act125.replaceAll("cc",""); 69 | 70 | double Act125=Double.parseDouble(dispval_Act125); 71 | System.out.println(Act125); 72 | // 8) Compare Displacement of Dio and Activa 125 and print the Scooter name having better Displacement. 73 | if(dio>Act125) 74 | {System.out.println("Dio has good displacement");} 75 | {System.out.println("Activa 125 has good displacement");} 76 | 77 | // 9) Click FAQ from Menu 78 | driver.findElementByXPath("//a[text()='FAQ']").click(); 79 | // 10) Click Activa 125 BS-VI under Browse By Product 80 | driver.findElementByLinkText("Activa 125 BS-VI").click(); 81 | // 11) Click Vehicle Price 82 | driver.findElementByXPath("//a[@href='#6a']/i").click(); 83 | // 12) Make sure Activa 125 BS-VI selected and click submit 84 | String Act125VI=driver.findElementById("ModelID6").getText(); 85 | if(Act125VI.equalsIgnoreCase("Activa 125 BS-VI")) 86 | System.out.println("Activa 125 BS-VI is selected"); 87 | driver.findElementById("submit6").click(); 88 | // 13) click the price link 89 | driver.findElementByXPath("//table[@id='tblPriceMasterFilters']//a[1]").click(); 90 | //Move Control to new window 91 | Set win = driver.getWindowHandles(); 92 | ArrayList winlis = new ArrayList(win); 93 | driver.switchTo().window(winlis.get(1)); 94 | 95 | // 14) Go to the new Window and select the state as Tamil Nadu and city as Chennai 96 | Select state = new Select(driver.findElementById("StateID")); 97 | state.selectByVisibleText("Tamil Nadu"); 98 | Select city = new Select(driver.findElementById("CityID")); 99 | city.selectByVisibleText("Chennai"); 100 | 101 | 102 | // 15) Click Search 103 | driver.findElementByXPath("//button[text()='Search']").click(); 104 | // 16) Print all the 3 models and their prices 105 | Map map_Model_Price = new LinkedHashMap(); 106 | 107 | String strModel=""; 108 | String strPrice=""; 109 | 110 | 111 | for(int i=1;i<=3;i++) 112 | { 113 | strModel = driver.findElementByXPath("//table[@id='gvshow']//tr["+i+"]//td[contains(text(),'ACTIVA')]").getText(); 114 | strPrice = driver.findElementByXPath("//table[@id='gvshow']//tr["+i+"]//td[contains(text(),'ACTIVA')]/following-sibling::td").getText(); 115 | 116 | map_Model_Price.put(strModel, strPrice); 117 | 118 | } 119 | 120 | System.out.println("|Model----------Price|"); 121 | 122 | for(Entry each:map_Model_Price.entrySet()) 123 | { 124 | System.out.print("|"+each.getKey()+"----------"+each.getValue()); 125 | System.out.println(); 126 | } 127 | 128 | driver.quit(); 129 | 130 | 131 | 132 | // 17) Close the Browser 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /HpPavilion.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.JavascriptExecutor; 7 | import org.openqa.selenium.NoSuchElementException; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | import org.openqa.selenium.chrome.ChromeOptions; 10 | import org.openqa.selenium.interactions.Actions; 11 | import org.openqa.selenium.support.ui.ExpectedConditions; 12 | import org.openqa.selenium.support.ui.Select; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | 15 | public class HpPavilion { 16 | 17 | public static void main(String[] args) throws InterruptedException { 18 | // TODO Auto-generated method stub 19 | //1) Go to https://store.hp.com/in-en/ 20 | //System.setProperty("webdriver.chrome.silentOutput", "true"); 21 | 22 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 23 | //launching chromebrowser by disabling notifications 24 | ChromeOptions options=new ChromeOptions(); 25 | options.addArguments("--disable-notification"); 26 | ChromeDriver driver= new ChromeDriver(options); 27 | //to load URL 28 | driver.get("https://store.hp.com/in-en/"); 29 | //to maximise the browser 30 | driver.manage().window().maximize(); 31 | driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 32 | Thread.sleep(3000); 33 | /*try { 34 | driver.findElementByXPath("//button[text()='Accept Cookies']").click(); 35 | } 36 | catch (NoSuchElementException exception) { 37 | System.out.println("Exception2 is catched"); 38 | } 39 | 40 | try { 41 | driver.findElementByXPath("//span[@class='optly-modal-close close-icon']").click(); 42 | } 43 | catch (NoSuchElementException exception) { 44 | System.out.println("Exception1 is catched"); 45 | } 46 | */ 47 | boolean cookies=driver.findElementByXPath("//button[text()='Accept Cookies']").isDisplayed(); 48 | if(cookies==true) 49 | { driver.findElementByXPath("//button[text()='Accept Cookies']").click();} 50 | Thread.sleep(3000); 51 | 52 | boolean frm = driver.findElementByXPath("//iframe[@name='ifr_edmpopup']").isDisplayed(); 53 | // 54 | if (frm == true) { 55 | // driver.switchTo().frame("ifr_edmpopup"); 56 | driver.findElementByXPath("//span[@class='optly-modal-close close-icon']").click(); 57 | // driver.switchTo().defaultContent(); 58 | } 59 | // Thread.sleep(3000); 60 | //driver.findElementByXPath("//button[text()='Accept Cookies']").click(); 61 | //2) Mouse over on Laptops menu and click on Pavilion 62 | Actions builder=new Actions(driver); 63 | builder.moveToElement(driver.findElementByXPath("(//span[text()='Laptops'])[1]")).perform(); 64 | 65 | driver.findElementByXPath("(//span[text()='Pavilion'])[1]").click(); 66 | //3) Under SHOPPING OPTIONS -->Processor -->Select Intel Core i7 67 | JavascriptExecutor js = (JavascriptExecutor) driver; 68 | js.executeScript("window.scrollBy(0, 250)"); 69 | 70 | driver.findElementByXPath("(//span[text()='Processor'])[2]").click(); 71 | Thread.sleep(3000); 72 | WebDriverWait wait = new WebDriverWait(driver,30); 73 | //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Intel Core i7']/parent::a/input"))); 74 | //driver.findElementByXPath("//input[@class='product-filter-checkbox'])[2]").click(); 75 | //driver.findElementByXPath("//a/span[text()='Intel Core i7']").click(); 76 | driver.findElementByXPath("//span[text()='Intel Core i7']/parent::a/input").click(); 77 | 78 | //4) Hard Drive Capacity -->More than 1TB 79 | Thread.sleep(3000); 80 | driver.findElementByXPath("//a/span[text()='More than 1 TB']").click(); 81 | //5) Select Sort By: Price: Low to High 82 | Thread.sleep(3000); 83 | js.executeScript("window.scrollBy(0, 600)"); 84 | 85 | Select dropdown=new Select(driver.findElementByXPath("(//select[@id='sorter'])[1]")); 86 | dropdown.selectByValue("price_asc"); 87 | //6) Print the First resulting Product Name and Price 88 | Thread.sleep(3000); 89 | String productname = driver.findElementByXPath("(//a[@class='product-item-link'])[1]").getText(); 90 | System.out.println("The product name is"+productname); 91 | String price=driver.findElementByXPath("//span[@id='product-price-9580']/span").getText(); 92 | System.out.println("The product price is"+price); 93 | 94 | //7) Click on Add to Cart 95 | driver.findElementByXPath("//button[@data-url='https://store.hp.com/in-en/default/hp-pavilion-15-cs3008tx-8lx78pa.html']/span").click(); 96 | //close the popup (Don't miss out) 97 | driver.findElementByXPath("//div[@class='inside_closeButton fonticon icon-hclose']").click(); 98 | 99 | //8) Click on Shopping Cart icon --> Click on View and Edit Cart 100 | driver.findElementByXPath("//a[@title='Shopping Cart']").click(); 101 | driver.findElementByXPath("//a/span[text()='View and edit cart']").click(); 102 | 103 | //9) Check the Shipping Option --> Check availability at Pincode 104 | //driver.findElementByXPath("//strong[text()='Shipping Option']").click(); 105 | //driver.findElementByXPath("//div/input[@placeholder='Pincode']").click(); 106 | driver.findElementById("standard_delivery").click(); 107 | driver.findElementByXPath("//div/input[@placeholder='Pincode']").sendKeys("600128"); 108 | driver.findElementByXPath("//button[text()='check']").click(); 109 | //u have to inspect the element of instock 110 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[@class='available']"))).click(); 111 | System.out.println("The delivery of status is :: "+driver.findElementByXPath("//span[@class='available']").getText()); 112 | 113 | //10) Verify the order Total against the product price 114 | String subtotal = driver.findElementByXPath("//span[@data-th='Subtotal']").getText(); 115 | String st=subtotal.replaceAll("\\D",""); 116 | //int st1=Integer.parseInt(st); 117 | String ordertotal = driver.findElementByXPath("//td[@data-th='Order Total']/strong").getText(); 118 | String ot=subtotal.replaceAll("\\D",""); 119 | //int ot1=Integer.parseInt(ot); 120 | 121 | //11) Proceed to Checkout if Order Total and Product Price matches 122 | if(st.equals(ot)) 123 | { 124 | System.out.println("The order total and product price matches"); 125 | //Thread.sleep(3000); 126 | //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//button[@id='sendIsCAC'])[1]"))); 127 | //js.executeScript("window.scrollBy(0, 300)"); 128 | //driver.findElement(By.xpath("(//button[@id='sendIsCAC'])[1]")).click(); 129 | driver.findElementByXPath("(//button/span[text()='Proceed to Checkout'])[1]").click(); 130 | } 131 | else System.out.println("The product price doesnot match"); 132 | 133 | //12) Click on Place Order 134 | driver.findElementByXPath("//button/span[text()='Place Order']").click(); 135 | 136 | //13) Capture the Error message and Print 137 | String errormsg=driver.findElementByXPath("//div/span[text()='Please specify a payment method.']").getText(); 138 | System.out.println("The error message is"+errormsg); 139 | //14) Close Browser 140 | driver.close(); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /HpPaviliondispop.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.JavascriptExecutor; 7 | import org.openqa.selenium.NoSuchElementException; 8 | import org.openqa.selenium.UnexpectedAlertBehaviour; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.interactions.Actions; 12 | import org.openqa.selenium.remote.CapabilityType; 13 | import org.openqa.selenium.remote.DesiredCapabilities; 14 | import org.openqa.selenium.support.ui.ExpectedConditions; 15 | import org.openqa.selenium.support.ui.Select; 16 | import org.openqa.selenium.support.ui.WebDriverWait; 17 | 18 | public class HpPaviliondispop { 19 | 20 | public static void main(String[] args) throws InterruptedException { 21 | // TODO Auto-generated method stub 22 | //1) Go to https://store.hp.com/in-en/ 23 | //to disable the rendering message becoz of new chrome installation 24 | System.setProperty("webdriver.chrome.silentOutput", "true"); 25 | 26 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 27 | //launching chromebrowser by disabling notifications 28 | ChromeOptions options=new ChromeOptions(); 29 | options.addArguments("--disable-notification"); 30 | //to disable all types of popups coming up when running the code 31 | DesiredCapabilities cap = new DesiredCapabilities(); 32 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 33 | //merge is to combine disable notifications and unexpected popups up 34 | options.merge(cap); 35 | 36 | ChromeDriver driver= new ChromeDriver(options); 37 | //to load URL 38 | driver.get("https://store.hp.com/in-en/"); 39 | //to maximise the browser 40 | driver.manage().window().maximize(); 41 | driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 42 | Thread.sleep(3000); 43 | 44 | // 2) Mouse over on Laptops menu and click on Pavilion 45 | Actions builder=new Actions(driver); 46 | builder.moveToElement(driver.findElementByXPath("(//span[text()='Laptops'])[1]")).perform(); 47 | 48 | driver.findElementByXPath("(//span[text()='Pavilion'])[1]").click(); 49 | 50 | //3) Under SHOPPING OPTIONS -->Processor -->Select Intel Core i7 51 | JavascriptExecutor js = (JavascriptExecutor) driver; 52 | js.executeScript("window.scrollBy(0, 250)"); 53 | 54 | driver.findElementByXPath("(//span[text()='Processor'])[2]").click(); 55 | js.executeScript("window.scrollBy(0, 280)"); 56 | 57 | //Thread.sleep(3000); 58 | WebDriverWait wait = new WebDriverWait(driver,30); 59 | //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Intel Core i7']/parent::a/input"))); 60 | //driver.findElementByXPath("//input[@class='product-filter-checkbox'])[2]").click(); 61 | //driver.findElementByXPath("//a/span[text()='Intel Core i7']").click(); 62 | driver.findElementByXPath("//span[text()='Intel Core i7']/parent::a/input").click(); 63 | 64 | //4) Hard Drive Capacity -->More than 1TB 65 | Thread.sleep(3000); 66 | driver.findElementByXPath("//a/span[text()='More than 1 TB']").click(); 67 | //5) Select Sort By: Price: Low to High 68 | Thread.sleep(3000); 69 | //js.executeScript("window.scrollBy(0, 600)"); 70 | 71 | Select dropdown=new Select(driver.findElementByXPath("(//select[@id='sorter'])[1]")); 72 | dropdown.selectByValue("price_asc"); 73 | //6) Print the First resulting Product Name and Price 74 | Thread.sleep(3000); 75 | String productname = driver.findElementByXPath("(//a[@class='product-item-link'])[1]").getText(); 76 | System.out.println("The product name is"+productname); 77 | String price=driver.findElementByXPath("//span[@id='product-price-9580']/span").getText(); 78 | System.out.println("The product price is"+price); 79 | 80 | //7) Click on Add to Cart 81 | driver.findElementByXPath("//button[@data-url='https://store.hp.com/in-en/default/hp-pavilion-15-cs3008tx-8lx78pa.html']/span").click(); 82 | //close the popup (Don't miss out) 83 | driver.findElementByXPath("//div[@class='inside_closeButton fonticon icon-hclose']").click(); 84 | 85 | //8) Click on Shopping Cart icon --> Click on View and Edit Cart 86 | driver.findElementByXPath("//a[@title='Shopping Cart']").click(); 87 | driver.findElementByXPath("//a/span[text()='View and edit cart']").click(); 88 | 89 | //9) Check the Shipping Option --> Check availability at Pincode 90 | //driver.findElementByXPath("//strong[text()='Shipping Option']").click(); 91 | //driver.findElementByXPath("//div/input[@placeholder='Pincode']").click(); 92 | driver.findElementById("standard_delivery").click(); 93 | driver.findElementByXPath("//div/input[@placeholder='Pincode']").sendKeys("600128"); 94 | driver.findElementByXPath("//button[text()='check']").click(); 95 | //u have to inspect the element of instock 96 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[@class='available']"))).click(); 97 | System.out.println("The delivery of status is :: "+driver.findElementByXPath("//span[@class='available']").getText()); 98 | 99 | //10) Verify the order Total against the product price 100 | String subtotal = driver.findElementByXPath("//span[@data-th='Subtotal']").getText(); 101 | String st=subtotal.replaceAll("\\D",""); 102 | //int st1=Integer.parseInt(st); 103 | String ordertotal = driver.findElementByXPath("//td[@data-th='Order Total']/strong").getText(); 104 | String ot=subtotal.replaceAll("\\D",""); 105 | //int ot1=Integer.parseInt(ot); 106 | 107 | //11) Proceed to Checkout if Order Total and Product Price matches 108 | if(st.equals(ot)) 109 | { 110 | System.out.println("The order total and product price matches"); 111 | //Thread.sleep(3000); 112 | //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//button[@id='sendIsCAC'])[1]"))); 113 | //js.executeScript("window.scrollBy(0, 300)"); 114 | //driver.findElement(By.xpath("(//button[@id='sendIsCAC'])[1]")).click(); 115 | driver.findElementByXPath("(//button/span[text()='Proceed to Checkout'])[1]").click(); 116 | } 117 | else System.out.println("The product price doesnot match"); 118 | 119 | //12) Click on Place Order 120 | driver.findElementByXPath("//button/span[text()='Place Order']").click(); 121 | 122 | //13) Capture the Error message and Print 123 | String errormsg=driver.findElementByXPath("//div/span[text()='Please specify a payment method.']").getText(); 124 | System.out.println("The error message is"+errormsg); 125 | //14) Close Browser 126 | driver.close(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /JustDial.java: -------------------------------------------------------------------------------- 1 | package Seleniumcoding; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.Keys; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | 13 | public class JustDial { 14 | 15 | 16 | public static void main(String[] args) throws InterruptedException, IOException { 17 | //Launching Chromebrowser 18 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 19 | //To disable notifications 20 | ChromeOptions options= new ChromeOptions(); 21 | options.addArguments("--disable-notifications"); 22 | ChromeDriver driver=new ChromeDriver(options); 23 | System.setProperty("webdriver.chrome.silentOutput", "true"); 24 | 25 | //Maximize the browser 26 | driver.manage().window().maximize(); 27 | //Load the url 28 | driver.get("https://www.justdial.com/"); 29 | //Implicitly wait for 5 milliseconds 30 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 31 | //Change location to chennai 32 | driver.findElementByXPath("//input[@id='city']").click(); 33 | driver.findElementByXPath("//a[@id='Chennai']").click(); 34 | Thread.sleep(1000); 35 | driver.findElementByXPath("//span[@id='hotkeys_text_6']").click(); 36 | Thread.sleep(500); 37 | driver.findElementByXPath("(//span[@class='meditle lng_commn'])[1]").click(); 38 | Thread.sleep(500); 39 | driver.findElementByXPath("(//span[@class='meditle1 lng_commn'])[5]").click(); 40 | Thread.sleep(500); 41 | driver.findElementByXPath("(//span[text()='Hyundai Xcent'])[2]").click(); 42 | Thread.sleep(3000); 43 | driver.findElementByXPath("//a[text()='Location']").click(); 44 | Thread.sleep(1000); 45 | WebElement city = driver.findElementByXPath("//input[@name='sortbydist']"); 46 | Thread.sleep(1000); 47 | //city.clear(); 48 | city.sendKeys("Porur"); 49 | driver.findElementByXPath("(//b[text()='Porur'])[1]").click(); 50 | Thread.sleep(1000); 51 | List sortedCompanyName = new ArrayList(); 52 | List rating = driver.findElementsByXPath("(//span[@class='green-box'])"); 53 | List votes = driver.findElementsByXPath("//span[@class='green-box']/following-sibling::span[@class='rt_count lng_vote']"); 54 | List companyNam=driver.findElementsByXPath("//span[@class='lng_cont_name']"); 55 | List phone=driver.findElementsByXPath("//p[@class='contact-info ']"); 56 | 57 | for (int i=0;i=4.5) 62 | { 63 | String vot=votes.get(i).getText(); 64 | String replacevot=vot.replaceAll("[^0-9]", ""); 65 | String vottrim=replacevot.trim(); 66 | int finalvotes=Integer.parseInt(vottrim); 67 | if (finalvotes>=50) 68 | { 69 | String name=companyNam.get(i).getText(); 70 | System.out.println(name); 71 | sortedCompanyName.add(name); 72 | String phoneNo=phone.get(i).getText(); 73 | System.out.println(phoneNo); 74 | 75 | } 76 | } 77 | } 78 | 79 | 80 | 81 | 82 | 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /MakeMytrip.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.Alert; 9 | import org.openqa.selenium.By; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.support.ui.ExpectedConditions; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | 15 | public class MakeMytrip { 16 | 17 | @SuppressWarnings("deprecation") 18 | public static void main(String[] args) throws InterruptedException { 19 | // TODO Auto-generated method stub 20 | //1) Go to https://www.makemytrip.com/ 21 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 22 | //launching chromebrowser by disabling notifications 23 | ChromeOptions options=new ChromeOptions(); 24 | options.addArguments("--disable-notification"); 25 | ChromeDriver driver= new ChromeDriver(options); 26 | //to load URL 27 | driver.get("https://www.makemytrip.com/"); 28 | //to maximise the browser 29 | driver.manage().window().maximize(); 30 | driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS); 31 | 32 | WebDriverWait wait = new WebDriverWait(driver, 30); 33 | // 2) Click Hotels 34 | driver.findElementByXPath("//span[text()='Hotels']").click(); 35 | // 3) Enter city as Goa, and choose Goa, India 36 | driver.findElementByXPath("//div[contains(@class,'hsw_inputBox selectHtlCity')]").click(); 37 | Thread.sleep(2000); 38 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@placeholder='Enter city/ Hotel/ Area/ Building']"))); 39 | driver.findElementByXPath("//input[@placeholder='Enter city/ Hotel/ Area/ Building']").sendKeys("Goa"); 40 | //choose goa 41 | driver.findElementByXPath("(//div[@class='flexOne']/p[contains(text(),Goa)])[1]").click(); 42 | // 4) Enter Check in date as Next month 15th (May 15) and Check out as start date+5 43 | driver.findElementByXPath("//div[@aria-label='Fri May 15 2020']").click(); 44 | driver.findElementByXPath("//span[text()='Select Checkout Date']").click(); 45 | driver.findElementByXPath("//div[@aria-label='Tue May 19 2020']").click(); 46 | // 5) Click on ROOMS & GUESTS and click 2 Adults and one Children(age 11). 47 | //Click Apply Button. 48 | driver.findElementByXPath("//input[@id='guest']").click(); 49 | driver.findElementByXPath("(//div[@class='addRooomDetails']//li)[2]").click(); 50 | driver.findElementByXPath("(//div[@class='addRooomDetails']//li)[14]").click(); 51 | driver.findElementByXPath("//button[text()='APPLY']").click(); 52 | // 6) Click Search button 53 | driver.findElementByXPath("//button[text()='Search']").click(); 54 | // 7) Select locality as Baga 55 | //as screen is blacked out 56 | driver.findElementByXPath("//div[@class='mmBackdrop wholeBlack']").click(); 57 | driver.findElementByXPath("//span[@class='checkmarkOuter']/label[text()='Baga']").click(); 58 | // 8) Select 5 start in Star Category under Select Filters 59 | driver.findElementByXPath("//span[@class='checkmarkOuter']/label[text()='5 Star']").click(); 60 | // 9) Click on the first resulting hotel and go to the new window 61 | driver.findElementByXPath("//span[text()='Acron Waterfront Resort-Member ITC Hotel Group']").click(); 62 | Set winSet=driver.getWindowHandles(); 63 | List winList=new ArrayList(winSet); 64 | //Switching the context to the second window 65 | driver.switchTo().window(winList.get(1)); 66 | // 10) Print the Hotel Name 67 | String hotelname=driver.findElementByXPath("//h1[text()='Acron Waterfront Resort-Member ITC Hotel Group']").getText(); 68 | System.out.println(hotelname); 69 | // 11) Click MORE OPTIONS link and Select 3Months plan and close 70 | driver.findElementByXPath("//span[text()='MORE OPTIONS']").click(); 71 | driver.findElementByXPath("//tr[2]/td[6]").click(); 72 | driver.findElementByXPath("//span[@class='close']").click(); 73 | // 12) Click on BOOK THIS NOW 74 | driver.findElementByXPath("//a[text()='BOOK THIS NOW']").click(); 75 | // 13) Print the Total Payable amount 76 | String totalpayamount=driver.findElementByXPath("//span[@id='revpg_total_payable_amt']").getText(); 77 | System.out.println("The total payable amount"+totalpayamount); 78 | //have to handle sweet alert 79 | driver.findElementByXPath("//span[@class='close']").click(); 80 | //Alert alert = driver.switchTo().alert(); 81 | //driver.findElementByXPath("//p[@class='latoBlack font22 blackText appendBottom5']"); 82 | //alert.dismiss(); 83 | // 14) Close the browser 84 | //close all the pages 85 | driver.quit(); 86 | 87 | 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /Myntra.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.support.ui.ExpectedConditions; 14 | import org.openqa.selenium.support.ui.Select; 15 | import org.openqa.selenium.support.ui.WebDriverWait; 16 | 17 | public class Myntra { 18 | 19 | @SuppressWarnings("deprecation") 20 | public static void main(String[] args) throws InterruptedException { 21 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 22 | //launching chromebrowser 23 | ChromeOptions options=new ChromeOptions(); 24 | options.addArguments("--disable-notification"); 25 | ChromeDriver driver= new ChromeDriver(options); 26 | //to load URL 27 | driver.get("https://www.myntra.com/"); 28 | //to maximise the browser 29 | driver.manage().window().maximize(); 30 | driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS); 31 | //1.Mouse over on WOMEN(Actions-->moveToElement) 32 | WebElement mouseHover = driver.findElementByXPath("//a[text()='Women']"); 33 | Actions builder=new Actions(driver); 34 | builder.moveToElement(mouseHover).perform(); 35 | //2.click jackets and coats 36 | driver.findElementByXPath("//a[text()='Jackets & Coats']").click(); 37 | 38 | //3.Find the total count of item (top) -> getText -> String 39 | 40 | String str = driver.findElementByClassName("title-count").getText(); 41 | 42 | String text = str.replaceAll("\\D","") ; 43 | int totalcount=Integer.parseInt(text) ; 44 | //4.Validate the sum of categories count matches 45 | String str1=driver.findElementByXPath("(//span[@class='categories-num'])[1]").getText(); 46 | String text1 = str1.replaceAll("\\D","") ; 47 | 48 | int Jacketcount=Integer.parseInt(text1); 49 | 50 | String str2=driver.findElementByXPath("(//span[@class='categories-num'])[2]").getText(); 51 | String text2 = str2.replaceAll("\\D","") ; 52 | int Coatcount=Integer.parseInt(text2); 53 | 54 | int Totalclothcount= Jacketcount+Coatcount; 55 | 56 | if(totalcount==Totalclothcount) 57 | System.out.println("the count matches"); 58 | else 59 | System.out.println("the count doesnot match"); 60 | //6. Check Coats 61 | 62 | WebElement radiobut=driver.findElementByXPath("(//div[@class='common-checkboxIndicator'])[2]"); 63 | radiobut.click(); 64 | //System.out.println(radiobut.isSelected()); 65 | //7.click brandmore 66 | driver.findElementByClassName("brand-more").click(); 67 | //8.type mango and click checkbox 68 | driver.findElementByClassName("FilterDirectory-searchInput").sendKeys("MANGO"); 69 | //label[@class=' common-customCheckbox']/div 70 | //click checkbox 71 | driver.findElementByXPath("//label[@class=' common-customCheckbox']/div").click(); 72 | //9.close the popup 73 | driver.findElementByXPath("//div[@class='FilterDirectory-titleBar']/span").click(); 74 | //10.Confirm all the Coats are of brand MANGO 75 | //findElements (brand) -> List 76 | //foreach -> getText of each brand 77 | //compare > if(condition 78 | Thread.sleep(10000); 79 | List brandList=driver.findElementsByClassName("product-brand"); 80 | int counter=0; 81 | for(WebElement eachBrand:brandList) 82 | { 83 | 84 | String brand=eachBrand.getText(); 85 | //System.out.println("brands name"+brand); 86 | counter++; 87 | } 88 | System.out.println(counter); 89 | 90 | //11) Sort by Better Discount 91 | Thread.sleep(5000); 92 | WebDriverWait wait = new WebDriverWait(driver,30); 93 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("sort-sortBy"))); 94 | Actions action2=new Actions(driver); 95 | action2.moveToElement(driver.findElementByClassName("sort-sortBy")).perform(); 96 | driver.findElementByXPath("//label[text()='Better Discount']").click(); 97 | //12)Find the price of first displayed item 98 | //findElements (price) -> List 99 | //get(0) -> WebElement -> getText -> String -> int 100 | Thread.sleep(5000); 101 | List pricelist = driver.findElementsByXPath("//span[@class='product-discountedPrice']"); 102 | String price=pricelist.get(0).getText().replaceAll("\\D", ""); 103 | System.out.println("The price of first displayed item "+price); 104 | Thread.sleep(5000); 105 | //13.13) Mouse over on size of the first item 106 | Actions action1 = new Actions(driver); 107 | action1. moveToElement(driver.findElementByXPath("(//div[@class='product-productMetaInfo'])[1]")).perform(); 108 | //action1. moveToElement(driver.findElementByXPath("(//h4[@class='product-sizes'])[1]")).perform(); 109 | 110 | 111 | //14) Click on WishList Now 112 | //driver.findElement(By.xpath("//span[text()='wishlist now']")).click(); 113 | 114 | Thread.sleep(5000); 115 | driver.findElementByXPath("(//div[@class='product-actions product-prelaunchActions']/span)[1]").click(); 116 | 117 | driver.close(); 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /Nykaa.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.interactions.Actions; 12 | 13 | public class Nykaa { 14 | public static void main(String[] args) throws InterruptedException 15 | { 16 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 17 | //launching chromebrowser by disabling notifications 18 | ChromeOptions options=new ChromeOptions(); 19 | options.addArguments("--disable-notification"); 20 | ChromeDriver driver= new ChromeDriver(options); 21 | //to load URL 22 | driver.get("https://www.nykaa.com/"); 23 | //to maximise the browser 24 | driver.manage().window().maximize(); 25 | driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS); 26 | //2) Mouseover on Brands and Mouseover on Popular 27 | Actions builder=new Actions(driver); 28 | WebElement ele=driver.findElementByXPath("//a[text()='brands']"); 29 | WebElement ele1=driver.findElementByXPath("//a[text()='Popular']"); 30 | 31 | builder.moveToElement(ele).moveToElement(ele1).perform(); 32 | //3) Click L'Oreal Paris 33 | driver.findElementByXPath("(//li[@class='brand-logo menu-links'])[5]").click(); 34 | 35 | 36 | 37 | //4) Go to the newly opened window and check the title contains L'Oreal Paris 38 | //write window handle code 39 | //window handle 40 | Set winSet=driver.getWindowHandles(); 41 | List winList=new ArrayList(winSet); 42 | //Switching the context to the second window 43 | driver.switchTo().window(winList.get(1)); 44 | if(driver.getTitle().contains("L'Oreal Paris")) 45 | System.out.println("The new window has the title"); 46 | else System.out.println("The window doesnot hav title"); 47 | 48 | //5) Click sort By and select customer top rated 49 | 50 | driver.findElementByXPath("//span[text()='Sort By : ']").click(); 51 | //Customer top rated 52 | driver.findElementByXPath("//span[text()='customer top rated']").click(); 53 | 54 | //6) Click Category and click Shampoo 55 | Thread.sleep(5000); 56 | driver.findElementByXPath("(//div[@class='filter-sidebar__filter-title pull-left'])[1]").click(); 57 | driver.findElementByXPath("(//label[@for='chk_Shampoo_undefined']/span)[1]").click(); 58 | //7) check whether the Filter is applied with Shampoo 59 | driver.findElementByXPath("(//div[@class='filter-applied']/following::li)[1]"); 60 | //8) Click on L'Oreal Paris Colour Protect Shampoo 61 | driver.findElementByXPath("//img[@alt=\"L'Oreal Paris Colour Protect Shampoo\"]").click(); 62 | //9) GO to the new window and select size as 175ml 63 | //now get the window handles too 64 | Set winSet1=driver.getWindowHandles(); 65 | List winList1=new ArrayList(winSet1); 66 | driver.switchTo().window(winList1.get(2)); 67 | String title=driver.getTitle(); 68 | System.out.println(title); 69 | Thread.sleep(2000); 70 | driver.findElementByXPath("//span[text()='175ml']").click(); 71 | //driver.findElementByXPath("(//span[@class='size-pallets'])[2]").click(); 72 | Thread.sleep(2000); 73 | //10) Print the MRP of the product 74 | String shampooprice=driver.findElementByXPath("(//span[@class='post-card__content-price-offer'])[1]").getText(); 75 | String price=shampooprice.replaceAll("\\D",""); 76 | int pricevalue=Integer.parseInt(price); 77 | System.out.println(pricevalue); 78 | Thread.sleep(2000); 79 | //11) Click on ADD to BAG 80 | driver.findElementByXPath("//div[@class='pdp-tile-add-to-cart-wrapper']/button").click(); 81 | Thread.sleep(2000); 82 | //12) Go to Shopping Bag 83 | driver.findElementByXPath("//div[@class='AddBagIcon']").click(); 84 | Thread.sleep(2000); 85 | //13) Print the Grand Total amount 86 | String pr1=driver.findElementByXPath("//div[@class='value medium-strong']").getText(); 87 | //String pr2=pr1.replaceAll("\\D",""); 88 | //int prval=Integer.parseInt(pr2); 89 | System.out.println("The grand total amount is"+pr1); 90 | //14) Click Proceed 91 | driver.findElementByXPath("//span[text()='Proceed']").click(); 92 | 93 | //15) Click on Continue as Guest 94 | driver.findElementByXPath("//button[text()='CONTINUE AS GUEST']").click(); 95 | 96 | //16) Print the warning message (delay in shipment) 97 | String warningmsg=driver.findElementByXPath("//div[text()='Please expect delay in shipments because of the national lockdown']").getText(); 98 | System.out.println(warningmsg); 99 | //17) Close all windows 100 | driver.quit(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Pepperfry.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.apache.commons.io.FileUtils; 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.JavascriptExecutor; 10 | import org.openqa.selenium.Keys; 11 | import org.openqa.selenium.OutputType; 12 | import org.openqa.selenium.UnexpectedAlertBehaviour; 13 | import org.openqa.selenium.WebElement; 14 | import org.openqa.selenium.chrome.ChromeDriver; 15 | import org.openqa.selenium.chrome.ChromeOptions; 16 | import org.openqa.selenium.interactions.Actions; 17 | import org.openqa.selenium.remote.CapabilityType; 18 | import org.openqa.selenium.remote.DesiredCapabilities; 19 | import org.openqa.selenium.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.WebDriverWait; 21 | 22 | public class Pepperfry { 23 | 24 | public static void main(String[] args) throws InterruptedException, IOException { 25 | //1) Go to https://www.pepperfry.com/ 26 | 27 | System.setProperty("webdriver.chrome.silentOutput", "true"); 28 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 29 | // disable the notifications 30 | ChromeOptions options = new ChromeOptions(); 31 | options.addArguments("--disable-notifications"); 32 | DesiredCapabilities cap = new DesiredCapabilities(); 33 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 34 | options.merge(cap); 35 | // Launching Chrome Browser 36 | ChromeDriver driver = new ChromeDriver(options); 37 | // To Load the url 38 | driver.get("https://www.pepperfry.com/"); 39 | // To maximize the browser 40 | driver.manage().window().maximize(); 41 | Actions action=new Actions(driver); 42 | // implicitly wait 43 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 44 | JavascriptExecutor js= (JavascriptExecutor) driver; 45 | 46 | WebDriverWait wait=new WebDriverWait(driver,30); 47 | // 2) Mouseover on Furniture and click Office Chairs under Chairs 48 | //Thread.sleep(2000); 49 | //wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//a[@class='popup-close'])[5]"))).click(); 50 | //driver.findElementByXPath("(//a[@class='popup-close'])[5]").click(); 51 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//a[@class='level-top'])[1]"))); 52 | action.moveToElement(driver.findElementByXPath("(//a[@class='level-top'])[1]")).build().perform(); 53 | System.out.println("Pointed to Furniture"); 54 | wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Office Chairs"))); 55 | driver.findElementByLinkText("Office Chairs").click(); 56 | System.out.println("Office Chairs link clicked"); 57 | 58 | /* 59 | * WebElement furniture=driver.findElementByXPath("(//a[@class='level-top'])[1]"); 60 | WebElement offchairs=driver.findElementByLinkText("Office Chairs"); 61 | builder.moveToElement(furniture).perform(); 62 | builder.moveToElement(offchairs).click(); 63 | */ 64 | //3) click Executive Chairs 65 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//h5[text()='Executive Chairs']"))); 66 | action.moveToElement(driver.findElementByXPath("//h5[text()='Executive Chairs']")).click(); 67 | System.out.println("executive chairs link clicked"); 68 | 69 | 70 | // 4) Change the minimum Height as 50 in under Dimensions 71 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//input[@class='clipFilterDimensionHeightValue'])[1]"))); 72 | driver.findElementByXPath("(//input[@class='clipFilterDimensionHeightValue'])[1]").clear(); 73 | driver.findElementByXPath("(//input[@class='clipFilterDimensionHeightValue'])[1]").sendKeys("50",Keys.ENTER); 74 | System.out.println("Minium Height filter set to 50"); 75 | 76 | // 5) Add "Poise Executive Chair in Black Colour" chair to Wishlist 77 | Thread.sleep(2000); 78 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@data-productname='Poise Executive Chair in Black Colour']"))); 79 | 80 | driver.findElementByXPath("//a[@data-productname='Poise Executive Chair in Black Colour']").click(); 81 | System.out.println("Poise Executive Chair in Black Colour is added to Wishlist"); 82 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='regPopUp']//a[@class='popup-close']"))); 83 | driver.findElement(By.xpath("//div[@id='regPopUp']//a[@class='popup-close']")).click(); 84 | 85 | // 6) Mouseover on Homeware and Click Pressure Cookers under Cookware 86 | //Thread.sleep(2000); 87 | 88 | //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='menu_wrapper']//a[text()='Homeware']"))); 89 | //WebElement homeware=driver.findElementByXPath("(//a[text()='Homeware'])[1]"); 90 | action.moveToElement(driver.findElementByXPath("//div[@id='menu_wrapper']//a[text()='Homeware']")).perform(); 91 | //System.out.println(); 92 | //Thread.sleep(2000); 93 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Pressure Cookers']"))); 94 | //WebElement pressurecook=driver.findElementByLinkText("Pressure Cookers"); 95 | driver.findElementByXPath("//a[text()='Pressure Cookers']").click(); 96 | System.out.println("Pressure Cookers clicked"); 97 | 98 | // 7) Select Prestige as Brand 99 | Thread.sleep(2000); 100 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@for='brandsnamePrestige']"))); 101 | 102 | driver.findElementByXPath("//label[@for='brandsnamePrestige']").click(); 103 | System.out.println("Brand Filter applied as Prestige"); 104 | 105 | // 8) Select Capacity as 1-3 Ltr 106 | Thread.sleep(1000); 107 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@for='capacity_db1_Ltr_-_3_Ltr']"))); 108 | driver.findElementByXPath("//label[@for='capacity_db1_Ltr_-_3_Ltr']").click(); 109 | System.out.println("Capacity filter applied as 1Ltr - 3Ltr"); 110 | 111 | // 9) Add "Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr" to Wishlist 112 | Thread.sleep(1000); 113 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@data-productname='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr']"))); 114 | driver.findElementByXPath("//a[@data-productname='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr']").click(); 115 | System.out.println("Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr added to Wishlist"); 116 | 117 | // 10) Verify the number of items in Wishlist 118 | ////div[@class='wishlist_bar']//span[1] 119 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='wishlist_bar']//span[1]"))); 120 | String numitems=driver.findElementByXPath("//div[@class='wishlist_bar']//span[1]").getText(); 121 | System.out.println("The number of items in wishlist"+numitems); 122 | // 11) Navigate to Wishlist 123 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@class,'pf-icon pf-icon-heart')]"))); 124 | driver.findElementByXPath("//a[contains(@class,'pf-icon pf-icon-heart')]").click(); 125 | System.out.println("navigating to wishlist"); 126 | // 12) Move Pressure Cooker only to Cart from Wishlist 127 | //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//a[@class='addtocart_icon'])[2]"))); 128 | WebElement cooker=driver.findElementByXPath("(//a[@class='addtocart_icon'])[2]"); 129 | js.executeScript("arguments[0].click()",cooker); 130 | System.out.println("Move Pressure Cooker only to Cart from Wishlist"); 131 | // 13) Check for the availability for Pincode 600128 132 | wait.until(ExpectedConditions.elementToBeClickable(By.className("srvc_pin_text"))); 133 | driver.findElementByClassName("srvc_pin_text").sendKeys("600128"); 134 | driver.findElementByClassName("check_available").click(); 135 | System.out.println("Check for the availability for Pincode 600128"); 136 | // 14) Click Proceed to Pay Securely 137 | Thread.sleep(500); 138 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(),'Proceed to pay securely')]"))); 139 | driver.findElementByXPath("//a[contains(text(),'Proceed to pay securely')]").click(); 140 | // 15 Click Proceed to Pay 141 | driver.findElementByClassName("btn_green_big").click(); 142 | // 16) Capture the screenshot of the item under Order Item 143 | //li[@role='option']//figure[1] parent based attribute xpath for the figure 144 | Thread.sleep(1000); 145 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='ORDER SUMMARY']"))); 146 | 147 | driver.findElementByXPath("//span[text()='ORDER SUMMARY']").click(); 148 | //js.executeScript("arguments[0].click()", osumm); 149 | 150 | //WebElement screenShotEle = driver.findElement(By.xpath("//div[@class='slick-track']//li")); 151 | WebElement screenShotEle = driver.findElementByTagName("figure"); 152 | File src = screenShotEle.getScreenshotAs(OutputType.FILE); 153 | File dest = new File("./screenshot/img.png"); 154 | FileUtils.copyFile(src, dest); 155 | System.out.println("Element Screenshot captured under screenshot folder successfully. File Name : img.png"); 156 | //17) Close the browser 157 | driver.close(); 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MySeleniumLearningJourney 2 | Automated various UI functionalities and have come across with various scenarios like selecting various products from different categories,adding them to cart, 3 | adding or deleting items in the cart according to our requirement,Placing order after making payment through payment gateway,as well as adding frequently needed 4 | items in the wish list for most of the websites: Amazon, Ajio, AirBnB, Best buy, 5 | Paypal, Justdial, BigBasket, Carwale, Crmcloud, Honda, Azure, MakeMyTrip, HPSite, Triviago, Shiksha, Myntra, SnapDeal, Zalando, Nykaa, Pepperfry, 6 | Azure, Naukri 7 | 8 | (a)Naukri website automation--->Automated the retrieval of each company name from the child window and also automated the complete resume upload process 9 | 10 | (b)MakeMyTrip/Trivago –-> Automated Searching of hotels, Sorting based on various input parameters like, rating, recommendations, number of reviews, deals, etc., 11 | Selecting hotels based on the high/low costs, Filtering of hotels based on the star value and different comfort options and Booking of hotels including 12 | payment options. 13 | 14 | (c)Honda-->Selecting Honda 2 wheeler based on mileage,body frame,colour,various categories,Comparing the prices against the other brands of Honda. 15 | -------------------------------------------------------------------------------- /Shiksha.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Map.Entry; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import org.openqa.selenium.JavascriptExecutor; 12 | import org.openqa.selenium.UnexpectedAlertBehaviour; 13 | import org.openqa.selenium.WebElement; 14 | import org.openqa.selenium.chrome.ChromeDriver; 15 | import org.openqa.selenium.chrome.ChromeOptions; 16 | import org.openqa.selenium.interactions.Actions; 17 | import org.openqa.selenium.remote.CapabilityType; 18 | import org.openqa.selenium.remote.DesiredCapabilities; 19 | import org.openqa.selenium.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.Select; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | 23 | public class Shiksha { 24 | 25 | public static void main(String[] args) throws InterruptedException { 26 | // TODO Auto-generated method stub 27 | System.setProperty("webdriver.chrome.silentOutput", "true"); 28 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 29 | // disable the notifications 30 | ChromeOptions options = new ChromeOptions(); 31 | options.addArguments("--disable-notifications"); 32 | 33 | DesiredCapabilities cap = new DesiredCapabilities(); 34 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 35 | options.merge(cap); 36 | // Launching Chrome Browser 37 | ChromeDriver driver = new ChromeDriver(options); 38 | // To Load the url 39 | driver.get("https://studyabroad.shiksha.com/"); 40 | // To maximize the browser 41 | driver.manage().window().maximize(); 42 | // implicitly wait 43 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 44 | WebDriverWait wait = new WebDriverWait(driver, 10); 45 | JavascriptExecutor js = (JavascriptExecutor) driver; 46 | Actions action=new Actions(driver); 47 | 48 | // 1) Go to https://studyabroad.shiksha.com/ 49 | // 2) Mouse over on Colleges and click MS in Computer Science &Engg under MS Colleges 50 | WebElement colleges=driver.findElementByXPath("(//label[contains(text(),'Colleges')])[2]"); 51 | WebElement MScompsci=driver.findElementByXPath("//a[text()='MS in Computer Science &Engg']"); 52 | action.moveToElement(colleges).build().perform(); 53 | // action.moveToElement(MScompsci).click(); 54 | MScompsci.click(); 55 | Thread.sleep(1000); 56 | 57 | // 3) Select GRE under Exam Accepted and Score 300 & Below 58 | WebElement GRE=driver.findElementByXPath("//label[@for='exam-0']//span[1]"); 59 | js.executeScript("arguments[0].click()", GRE); 60 | Thread.sleep(1000); 61 | WebElement score300=driver.findElementByXPath("(//select[@class='score-select-field'])[1]"); 62 | WebElement match=driver.findElementByClassName("score-select-field"); 63 | Select select=new Select(match); 64 | select.selectByVisibleText("284 & below"); 65 | Thread.sleep(1000); 66 | // 4) Max 10 Lakhs under 1st year Total fees, USA under countries 67 | WebElement max10l=driver.findElementByXPath("//label/p[text()='Max 10 Lakhs']"); 68 | max10l.click(); 69 | Thread.sleep(1000); 70 | WebElement usa=driver.findElementByXPath("//a[text()='USA']/ancestor::label/span"); 71 | // wait.until(ExpectedConditions.visibilityOfElementLocated("//a[text()='USA']/ancestor::label/span")); 72 | js.executeScript("arguments[0].click()", usa); 73 | Thread.sleep(1000); 74 | // 5) Select Sort By: Low to high 1st year total fees 75 | WebElement sort=driver.findElementById("categorySorter"); 76 | Select select1=new Select(sort); 77 | select1.selectByValue("fees_ASC"); 78 | Thread.sleep(1000); 79 | // 6) Click Add to compare of the College having least fees with Public University, Scholarship and Accomadation 80 | //(1) first find the number of colleges count 81 | String collcount=driver.findElementByXPath("//span[@id='foundCoursesCount']").getText(); 82 | System.out.println("the colleges count"+collcount); 83 | int noofcol=Integer.parseInt(collcount.replaceAll("\\D","")); 84 | System.out.println("The number of colleges"+noofcol); 85 | //(2)get the colleges having 3 conditions tick in the map.So the map will contain only list of colleges 86 | // having 3 conditions ticked(public university,scholarship,accomadation 87 | //hash map doesnot maintain insertion order 88 | Map maps=new HashMap (); 89 | for(int i=1;i<=noofcol;i++) 90 | { String pubuniv=driver.findElementByXPath("(//p[text()='Public university']/span)["+i+"]").getAttribute("class"); 91 | System.out.println("the public univ tick is"+pubuniv +"and i is"+ i); 92 | String scholar=driver.findElementByXPath("(//p[text()='Scholarship']/span)["+i+"]").getAttribute("class"); 93 | System.out.println("the scholar is"+scholar+"and i is"+i); 94 | String accomodate=driver.findElementByXPath("(//p[text()='Accommodation']/span)["+i+"]").getAttribute("class"); 95 | System.out.println("the accomodate is"+accomodate+"and i is "+i); 96 | if(pubuniv.equalsIgnoreCase("tick-mark")&& scholar.equalsIgnoreCase("tick-mark")&& accomodate.equalsIgnoreCase("tick-mark")) 97 | { 98 | String annualfees= driver.findElementByXPath("(//div[@class='detail-col flLt']//p[contains(text(),'Rs')])["+i+"]").getText(); 99 | System.out.println("the annual fees of college"+ annualfees+ " and the number is"+ i ); 100 | float firstyrfees=Float.parseFloat(annualfees.replaceAll("[^0-9.]","")); 101 | maps.put(""+i,firstyrfees); 102 | } 103 | } 104 | //(3) add the firstyearfees value from map (map>value) to list,so as to apply sorting in list 105 | List sortedfees=new ArrayList (); 106 | for(Entry eachEntry:maps.entrySet()) 107 | { sortedfees.add(eachEntry.getValue()); 108 | System.out.println("printing map with college with 3 ticks"); 109 | System.out.println(eachEntry.getKey()+"--->"+eachEntry.getValue()); 110 | } 111 | //(4)after filling fees value in sortedfees list,apply collections.sort 112 | Collections.sort(sortedfees); 113 | Float lowestfees=sortedfees.get(0); 114 | //(5) now take the lowest fees and add the corresponding college (add to compare()) 115 | //using key which is to be got from map 116 | for (Entry eachEntry:maps.entrySet()) 117 | { 118 | if(eachEntry.getValue().equals(lowestfees)) 119 | { String college=eachEntry.getKey(); 120 | System.out.println("the college number is"+college); 121 | // (//p[text()='Add to compare'])[1] 122 | driver.findElementByXPath("(//p[contains(text(),'Add to compare')])["+college+"]").click(); 123 | break; 124 | } 125 | } 126 | 127 | System.out.println("The lowest annual fees is"+lowestfees); 128 | Thread.sleep(2000); 129 | 130 | // 7) Select the first college under Compare with similar colleges 131 | driver.findElementByXPath("(//span[@class='add-tag'])[1]").click(); 132 | System.out.println("selected the first college to compare"); 133 | Thread.sleep(1000); 134 | // 8) Click on Compare College> 135 | driver.findElementByXPath("//strong[text()='Compare Colleges >']").click(); 136 | System.out.println("clicked on compare colleges"); 137 | Thread.sleep(1000); 138 | // 9) Select When to Study as 2021 139 | driver.findElementByXPath("(//span[@class='common-sprite'])[2]").click(); 140 | Thread.sleep(500); 141 | // 11) Select Level of Study as Masters 142 | driver.findElementByXPath("(//span[@class='common-sprite'])[5]").click(); 143 | Thread.sleep(500); 144 | // 10) Select Preferred Countries as USA 145 | driver.findElementByXPath("(//div[contains(@class,'sp-frm selectCountryField')])[1]").click(); 146 | Thread.sleep(500); 147 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//label[contains(@for,'USA')]"))); 148 | driver.findElementByXPath("//label[contains(@for,'USA')]").click(); 149 | Thread.sleep(500); 150 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByClassName("ok-btn"))); 151 | 152 | driver.findElementByClassName("ok-btn").click(); 153 | Thread.sleep(500); 154 | // 12) Select Preferred Course as MS 155 | driver.findElementByXPath("(//div[contains(@class,'sp-frm selectField')])[1]").click(); 156 | Thread.sleep(500); 157 | driver.findElementByXPath("(//li[@class='lr-row'])[2]").click(); 158 | Thread.sleep(500); 159 | // 13) Select Specialization as "Computer Science & Engineering" 160 | driver.findElementByXPath("//div[text()='All specializations']").click(); 161 | Thread.sleep(1000); 162 | driver.findElementByXPath("//li[text()='Computer Science & Engineering']").click(); 163 | 164 | // 14) Click on Sign Up 165 | driver.findElementById("signup").click(); 166 | // 15) Print all the warning messages displayed on the screen for missed mandatory fields 167 | List errmessages=driver.findElementsByXPath("//div[@class='helper-text' and starts-with(text(),'Please')]"); 168 | for( WebElement errmsg:errmessages) 169 | 170 | { 171 | System.out.println("The error messages are"+errmsg.getText()); 172 | } 173 | 174 | //16.close the browser 175 | } 176 | 177 | } 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /SnapDeal.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Set; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.Keys; 9 | import org.openqa.selenium.UnexpectedAlertBehaviour; 10 | import org.openqa.selenium.WebElement; 11 | import org.openqa.selenium.chrome.ChromeDriver; 12 | import org.openqa.selenium.chrome.ChromeOptions; 13 | import org.openqa.selenium.interactions.Actions; 14 | import org.openqa.selenium.remote.CapabilityType; 15 | import org.openqa.selenium.remote.DesiredCapabilities; 16 | import org.openqa.selenium.support.ui.ExpectedConditions; 17 | import org.openqa.selenium.support.ui.WebDriverWait; 18 | 19 | public class SnapDeal { 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | // TODO Auto-generated method stub 23 | System.setProperty("webdriver.chrome.silentOutput", "true"); 24 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 25 | // disable the notifications 26 | ChromeOptions options = new ChromeOptions(); 27 | options.addArguments("--disable-notifications"); 28 | 29 | DesiredCapabilities cap = new DesiredCapabilities(); 30 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 31 | options.merge(cap); 32 | // Launching Chrome Browser 33 | ChromeDriver driver = new ChromeDriver(options); 34 | // To Load the url 35 | driver.get("https://www.snapdeal.com/"); 36 | // To maximize the browser 37 | driver.manage().window().maximize(); 38 | // implicitly wait 39 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 40 | WebDriverWait wait = new WebDriverWait(driver, 30); 41 | JavascriptExecutor js = (JavascriptExecutor) driver; 42 | Actions action=new Actions(driver); 43 | // 1) Go to https://www.snapdeal.com/ 44 | // ‎2) Mouse over on Toys, Kids' Fashion & more and click on Toys 45 | WebElement toys=driver.findElementByXPath("//span[text()=\"Toys, Kids' Fashion & more\"]"); 46 | action.moveToElement(toys).build().perform(); 47 | // Thread.sleep(1000); 48 | driver.findElementByXPath("//span[text()='Educational Toys']").click(); 49 | // 3) Click Educational Toys in Toys & Games 50 | // ‎4) Click the Customer Rating 4 star and Up 51 | driver.findElementByXPath("//label[@for='avgRating-4.0']").click(); 52 | // 5) Click the offer as 40-50 53 | Thread.sleep(1000); 54 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//label[@for='discount-40%20-%2050']"))); 55 | driver.findElementByXPath("//label[@for='discount-40%20-%2050']").click(); 56 | // driver.findElementByXPath("(//input[@checked='checked']/following-sibling::label)[1]").click(); 57 | // 6) Check the availability for the pincode 58 | // driver.findElementById("pincode-edit").click(); 59 | driver.findElementByXPath("//input[@placeholder='Enter your pincode']").sendKeys("600043",Keys.TAB); 60 | // driver.findElementByClassName("pincode-check").click(); 61 | driver.findElementByXPath("//button[text()='Check']").click(); 62 | // 7) Click the Quick View of the first product 63 | Thread.sleep(500); 64 | // wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//div[contains(@class,'center quick-view-bar')])[1]"))); 65 | // driver.findElementByXPath("(//img[@class='product-image wooble'])[1]").click(); 66 | //WebElement quickv=driver.findElementByXPath("(//div[contains(@class,'center quick-view-bar')])[1]"); 67 | // 8) Click on View Details 68 | 69 | WebElement quickv=driver.findElementByXPath("(//div[contains(text(),'Quick View')])[1]"); 70 | js.executeScript("arguments[0].click()",quickv); 71 | // action.moveToElement(quickv).build().perform(); 72 | // action.moveToElement(quickv).click(); 73 | // driver.findElementByLinkText("view details").click(); 74 | Thread.sleep(500); 75 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//a[contains(@class,'btn btn-theme-secondary')])[1]"))); 76 | driver.findElementByXPath("(//a[contains(@class,'btn btn-theme-secondary')])[1]").click(); 77 | // 8) Click on View Details 78 | // 9) Capture the Price of the Product and Delivery Charge 79 | String pr=driver.findElementByClassName("payBlkBig").getText(); 80 | System.out.println(pr); 81 | String pri=pr.replaceAll("\\D",""); 82 | int price=Integer.parseInt(pri); 83 | System.out.println(price); 84 | String del=driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 85 | System.out.println("the delivery chr"+del); 86 | String del1=del.replaceAll("\\D",""); 87 | int delchg=Integer.parseInt(del1); 88 | System.out.println("the cleansed del ch"+delchg); 89 | int total=price+delchg; 90 | System.out.println("the price of toy"+total); 91 | driver.findElementByXPath("//span[text()='add to cart']").click(); 92 | // 10) Validate the You Pay amount matches the sum of (price+deliver charge) 93 | 94 | // 11) Search for Sanitizer 95 | driver.findElementById("inputValEnter").sendKeys("Sanitizer",Keys.ENTER); 96 | // 12) Click on Product "BioAyurveda Neem Power Hand Sanitizer" 97 | driver.findElementByXPath("//p[@title='BioAyurveda Neem Power Hand Sanitizer 500 mL Pack of 1']").click(); 98 | // 13) Capture the Price and Delivery Charge 99 | Set win=driver.getWindowHandles(); 100 | ArrayList winlist=new ArrayList (win); 101 | driver.switchTo().window(winlist.get(1)); 102 | String sa_pr=driver.findElementByClassName("payBlkBig").getText(); 103 | String sa_pr1=sa_pr.replaceAll("\\D",""); 104 | int sa_price=Integer.parseInt(sa_pr1); 105 | System.out.println("The sanitizer price"+sa_price); 106 | String sa_dc=driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 107 | String sa_dc1=sa_dc.replaceAll("\\D",""); 108 | int sa_delch=Integer.parseInt(sa_dc1); 109 | System.out.println("the del ch of sanitizer"+sa_dc1); 110 | int sa_total=sa_price+sa_delch; 111 | System.out.println("the sanitizer total"+sa_total); 112 | // 14) Click on Add to Cart 113 | Thread.sleep(1000); 114 | driver.findElementByXPath("(//span[text()='ADD TO CART'])[1]").click(); 115 | // 15) Click on Cart 116 | Thread.sleep(2000); 117 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByClassName("cartTextSpan"))); 118 | driver.findElementByClassName("cartTextSpan").click(); 119 | // 16) Validate the Proceed to Pay matches the total amount of both the products 120 | int grandtotal=total+sa_total; 121 | System.out.println("The total value of cart is"+grandtotal); 122 | String button=driver.findElementByXPath("//input[@type='button']").getAttribute("value"); 123 | System.out.println(button); 124 | String button1=button.replaceAll("\\D",""); 125 | int totalamt=Integer.parseInt(button1); 126 | System.out.println("Proceed to pay match value"+totalamt); 127 | if(totalamt==grandtotal) 128 | System.out.println("The total matches"); 129 | else System.out.println("the total didnot match"); 130 | // 17) Close all the windows 131 | //driver.close(); 132 | 133 | driver.quit(); 134 | 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /Take Notes.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnithaDevi10/MySeleniumLearningJourney/5120b752aef8662d7b87017986b4c96ff1b2ecf7/Take Notes.docx -------------------------------------------------------------------------------- /TestAzure.java: -------------------------------------------------------------------------------- 1 | package SeleniumCoding; 2 | 3 | import java.io.File; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.Keys; 9 | import org.openqa.selenium.UnexpectedAlertBehaviour; 10 | import org.openqa.selenium.WebElement; 11 | import org.openqa.selenium.chrome.ChromeDriver; 12 | import org.openqa.selenium.chrome.ChromeOptions; 13 | import org.openqa.selenium.interactions.Actions; 14 | import org.openqa.selenium.remote.CapabilityType; 15 | import org.openqa.selenium.remote.DesiredCapabilities; 16 | import org.openqa.selenium.support.ui.ExpectedConditions; 17 | import org.openqa.selenium.support.ui.Select; 18 | import org.openqa.selenium.support.ui.WebDriverWait; 19 | 20 | public class TestAzure { 21 | 22 | public static void main(String[] args) throws InterruptedException { 23 | // TODO Auto-generated method stub 24 | // 1) Go to https://azure.microsoft.com/en-in/ 25 | System.setProperty("webdriver.chrome.silentOutput", "true"); 26 | System.setProperty("webdriver.chrome.driver", 27 | "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 28 | // disable the notifications 29 | ChromeOptions options = new ChromeOptions(); 30 | options.addArguments("--disable-notifications"); 31 | 32 | DesiredCapabilities cap = new DesiredCapabilities(); 33 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 34 | options.merge(cap); 35 | // Launching Chrome Browser 36 | ChromeDriver driver = new ChromeDriver(options); 37 | // To Load the url 38 | driver.get("https://azure.microsoft.com/en-in/"); 39 | // To maximize the browser 40 | driver.manage().window().maximize(); 41 | // implicitly wait 42 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 43 | WebDriverWait wait = new WebDriverWait(driver, 10); 44 | JavascriptExecutor js = (JavascriptExecutor) driver; 45 | Actions action=new Actions(driver); 46 | 47 | // 2) Click on Pricing 48 | driver.findElementById("navigation-pricing").click(); 49 | Thread.sleep(1000); 50 | // 3) Click on Pricing Calculator 51 | //driver.findElementByLinkText("Pricing calculator").click(); 52 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Azure pricing calculator']"))); 53 | driver.findElementByXPath("//span[text()='Azure pricing calculator']").click(); 54 | 55 | Thread.sleep(3000); 56 | // 4) Click on Containers 57 | WebElement containers=driver.findElementByXPath("//button[@data-event-property='containers']"); 58 | wait.until(ExpectedConditions.elementToBeClickable(containers)); 59 | 60 | js.executeScript("arguments[0].click()",containers); 61 | 62 | 63 | // 5) Select Container Instances 64 | driver.findElementByXPath("(//span[text()='Container Instances'])[3]").click(); 65 | // 6) Click on Container Instance Added View 66 | driver.findElementById("new-module-loc").click(); 67 | // 7) Select Region as "South India" 68 | WebElement region=driver.findElementByXPath("(//select[@name='region'])[1]"); 69 | Select dropdown=new Select(region); 70 | dropdown.selectByVisibleText("South India"); 71 | // 8) Set the Duration as 180000 seconds 72 | WebElement duration=driver.findElementByXPath("(//input[@aria-label='Seconds'])[1]"); 73 | duration.click(); 74 | duration.sendKeys(Keys.HOME, Keys.chord(Keys.SHIFT, Keys.END),"180000"); 75 | //keys.chord(Keys.CONTROL,"a"),"seonds value" 76 | 77 | 78 | // //input[@aria-label='Seconds'] 79 | 80 | // 9) Select the Memory as 4GB 81 | WebElement memory=driver.findElementByXPath("(//select[@class='select'])[3]"); 82 | Select memlist=new Select(memory); 83 | memlist.selectByVisibleText("4 GB"); 84 | // 10) Enable SHOW DEV/TEST PRICING 85 | driver.findElementById("devtest-toggler").click(); 86 | // 11) Select Indian Rupee as currency 87 | WebElement currency=driver.findElementByXPath("//select[@class='select currency-dropdown']"); 88 | Select currencylist=new Select(currency); 89 | currencylist.selectByVisibleText("Indian Rupee (₹)"); 90 | 91 | // 12) Print the Estimated monthly price 92 | ////section[@id='azure-calculator']/div[1]/div[2]/div[2]/div[1]/div[1]/section[1]/div[6]/div[1]/div[2]/div[2]/span[1]/span[1] 93 | String estmthprice=driver.findElementByXPath("(//div[@class='column large-3 text-right total']//span[@class='numeric'])[2]").getText(); 94 | System.out.println(estmthprice); 95 | // 13) Click on Export to download the estimate as excel 96 | driver.findElementByXPath("//button[text()='Export']").click(); 97 | // 14) Verify the downloded file in the local folder 98 | File f = new File("Macintosh HD/Users/kumanananitha/Downloads/ExportedEstimate(*).xlsx"); 99 | if(f.exists() ) { 100 | // do something 101 | System.out.println("File exists"); 102 | } 103 | else { System.out.println("file do not exist"); } 104 | // 15) Navigate to Example Scenarios and Select CI/CD for Containers 105 | Thread.sleep(2000); 106 | //WebElement example_scenary=driver.findElementByLinkText("Example Scenarios"); 107 | WebElement example_scenary=driver.findElementByXPath("//a[@href='solution-architectures-picker-panel']"); 108 | 109 | wait.until(ExpectedConditions.elementToBeClickable(example_scenary)); 110 | //example_scenary.click(); 111 | js.executeScript("arguments[0].click()",example_scenary); 112 | Thread.sleep(1000); 113 | WebElement CICDcontain=driver.findElementByXPath("//span[text()='CI/CD for Containers']"); 114 | wait.until(ExpectedConditions.elementToBeClickable(CICDcontain)); 115 | //CICDcontain.click(); 116 | js.executeScript("arguments[0].click()",CICDcontain); 117 | 118 | // 16) Click Add to Estimate 119 | WebElement addtoest=driver.findElementByXPath("//button[text()='Add to estimate']"); 120 | wait.until(ExpectedConditions.elementToBeClickable(addtoest)); 121 | //addtoest.click(); 122 | js.executeScript("arguments[0].click()",addtoest); 123 | 124 | Thread.sleep(3000); 125 | // 17) Change the Currency as Indian Rupee 126 | WebElement currlist=driver.findElementByXPath("//select[@class='select currency-dropdown']"); 127 | Select clist=new Select(currlist); 128 | clist.selectByVisibleText("Indian Rupee (₹)"); 129 | // 18) Enable SHOW DEV/TEST PRICING 130 | driver.findElementById("devtest-toggler").click(); 131 | Thread.sleep(500); 132 | //print the estimate 133 | String estimated=driver.findElementByXPath("(//div[@class='column large-3 text-right total']//span[@class='numeric'])[2]").getText(); 134 | System.out.println(estimated); 135 | // 19) Export the Estimate 136 | driver.findElementByXPath("//button[text()='Export']").click(); 137 | // 20) Verify the downloded file in the local folder 138 | File f1 = new File("Macintosh HD/Users/kumanananitha/Downloads/ExportedEstimate(*).xlsx"); 139 | if(f1.exists() ) { 140 | // do something 141 | System.out.println("File exists"); 142 | } 143 | else { System.out.println("file do not exist"); } 144 | 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /TestHonda.java: -------------------------------------------------------------------------------- 1 | package SeleniumCoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Map.Entry; 8 | import java.util.Set; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import org.openqa.selenium.WebElement; 12 | import org.openqa.selenium.chrome.ChromeDriver; 13 | import org.openqa.selenium.interactions.Actions; 14 | import org.openqa.selenium.support.ui.ExpectedConditions; 15 | import org.openqa.selenium.support.ui.Select; 16 | import org.openqa.selenium.support.ui.WebDriverWait; 17 | 18 | public class TestHonda { 19 | 20 | public static void main(String[] args) throws InterruptedException { 21 | // TODO Auto-generated method stub 22 | //1) Go to https://www.honda2wheelersindia.com/ 23 | //-------------------------------------------- 24 | 25 | System.setProperty("webdriver.chrome.driver", 26 | "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 27 | /*ChromeOptions options = new ChromeOptions(); 28 | 29 | options.addArguments("--disable-popup-blocking"); 30 | DesiredCapabilities capabilities = new DesiredCapabilities(); 31 | capabilities.setCapability(ChromeOptions.CAPABILITY, options);*/ 32 | // ChromeDriver driver = new ChromeDriver(capabilities); 33 | 34 | ChromeDriver driver = new ChromeDriver(); 35 | 36 | 37 | driver.get("https://www.honda2wheelersindia.com/"); 38 | 39 | driver.manage().window().maximize(); 40 | 41 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 42 | 43 | //close pop up 44 | //---------- 45 | 46 | driver.findElementByXPath("//button[@class='close']").click(); 47 | 48 | 49 | //2) Click on scooters and click dio 50 | //----------------------------------- 51 | 52 | WebDriverWait wait = new WebDriverWait(driver,30); 53 | Thread.sleep(2000); 54 | 55 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementById("link_Scooter"))); 56 | 57 | driver.findElementById("link_Scooter").click(); 58 | 59 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@class='owl-wrapper-outer']//a[contains(@href,'dio')]"))); 60 | 61 | driver.findElementByXPath("//div[@class='owl-wrapper-outer']//a[contains(@href,'dio')]").click(); 62 | 63 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 64 | 65 | 66 | //3) Click on Specifications and mouseover on ENGINE 67 | //------------------------------------------------ 68 | Thread.sleep(2000); 69 | 70 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//a[text()='Specifications']"))); 71 | 72 | Actions action = new Actions(driver); 73 | 74 | action.moveToElement(driver.findElementByXPath("//a[text()='Specifications']")).click().build().perform(); 75 | 76 | 77 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 78 | 79 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//a[text()='ENGINE']"))); 80 | 81 | 82 | 83 | action.moveToElement(driver.findElementByXPath("//a[text()='ENGINE']")).build().perform(); 84 | 85 | //4) Get Displacement value 86 | //---------------------- 87 | 88 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@class='engine part-2 axx']//span[text()='Displacement']/following-sibling::span"))); 89 | 90 | String strDisplacement_Dio = driver.findElementByXPath("//div[@class='engine part-2 axx']//span[text()='Displacement']/following-sibling::span").getText(); 91 | 92 | String[] arr = strDisplacement_Dio.split("cc"); 93 | 94 | strDisplacement_Dio = arr[0]; 95 | 96 | double dblDisplacement_Dio = Double.parseDouble(strDisplacement_Dio.trim()); 97 | 98 | //5) Go to Scooters and click Activa 125 99 | //----------------------------------------- 100 | 101 | driver.findElementById("link_Scooter").click(); 102 | 103 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@class='owl-wrapper-outer']//a[contains(@href,'activa125')]"))); 104 | 105 | driver.findElementByXPath("//div[@class='owl-wrapper-outer']//a[contains(@href,'activa125')]").click(); 106 | 107 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 108 | 109 | //6) Click on Specifications and mouseover on ENGINE 110 | //-------------------------------------------------- 111 | 112 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//a[text()='Specifications']"))); 113 | 114 | action.moveToElement(driver.findElementByXPath("//a[text()='Specifications']")).click().build().perform(); 115 | 116 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 117 | 118 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//a[text()='ENGINE']"))); 119 | 120 | action = new Actions(driver); 121 | 122 | action.moveToElement(driver.findElementByXPath("//a[text()='ENGINE']")).build().perform(); 123 | 124 | 125 | //7) Get Displacement value 126 | //------------------------- 127 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@class='engine part-4 axx']//span[text()='Displacement']/following-sibling::span"))); 128 | 129 | String strDisplacement_activa125 = driver.findElementByXPath("//div[@class='engine part-4 axx']//span[text()='Displacement']/following-sibling::span").getText(); 130 | arr = strDisplacement_activa125.split("cc"); 131 | 132 | strDisplacement_activa125 = arr[0]; 133 | 134 | double dblDisplacementActiva125 = Double.parseDouble(strDisplacement_activa125.trim()); 135 | 136 | 137 | //8) Compare Displacement of Dio and Activa 125 and print the Scooter name having better Displacement. 138 | //-------------------------------------------------------------------------------------------------- 139 | 140 | if(dblDisplacement_Dio>dblDisplacementActiva125) 141 | { 142 | System.out.println("Dio has better Displacement"); 143 | } 144 | else 145 | { 146 | System.out.println("Activa125 has better Displacement"); 147 | } 148 | 149 | 150 | //9) Click FAQ from Menu 151 | //--------------------- 152 | 153 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//ul[@class='nav navbar-nav']//a[text()='FAQ']"))); 154 | 155 | driver.findElementByXPath("//ul[@class='nav navbar-nav']//a[text()='FAQ']").click(); 156 | 157 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 158 | 159 | //10) Click Activa 125 BS-VI under Browse By Product 160 | //----------------------------------------------------------- 161 | 162 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[text()='Activa 125 BS-VI']"))); 163 | 164 | driver.findElementByXPath("//a[text()='Activa 125 BS-VI']").click(); 165 | 166 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 167 | 168 | 169 | //11) Click Vehicle Price 170 | //---------------------- 171 | 172 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//ul[contains(@class,'nav nav-pills tabb-design')]//a[contains(text(),'Vehicle Price')]"))); 173 | 174 | action.moveToElement(driver.findElementByXPath("//ul[contains(@class,'nav nav-pills tabb-design')]//a[contains(text(),'Vehicle Price')]")).click().build().perform(); 175 | 176 | 177 | //12) Make sure Activa 125 BS-VI selected and click submit 178 | //----------------------------------------------------------- 179 | 180 | 181 | WebElement ele = driver.findElementById("ModelID6"); 182 | 183 | Select slt = new Select(ele); 184 | 185 | String selectedValue = slt.getFirstSelectedOption().getText(); 186 | 187 | if(selectedValue.contains("Activa 125 BS")) 188 | { 189 | System.out.println("Activa 125 BS-VI is selected"); 190 | } 191 | 192 | action.moveToElement(driver.findElementById("submit6")).click().build().perform(); 193 | 194 | 195 | //13) click the price link 196 | //------------------------- 197 | 198 | 199 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[contains(text(),'Click here to know the price of')]"))); 200 | 201 | driver.findElementByXPath("//a[contains(text(),'Click here to know the price of')]").click(); 202 | 203 | 204 | //14) Go to the new Window and select the state as Tamil Nadu and city as Chennai 205 | //------------------------------------------------------------------------------ 206 | 207 | Set windowHandles = driver.getWindowHandles(); 208 | 209 | List lstwindowHandles = new ArrayList(windowHandles); 210 | 211 | if(lstwindowHandles.size()==2) 212 | { 213 | 214 | driver.switchTo().window(lstwindowHandles.get(1)); 215 | 216 | driver.manage().window().maximize(); 217 | 218 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 219 | } 220 | 221 | 222 | 223 | wait.until(ExpectedConditions.visibilityOf(driver.findElementById("StateID"))); 224 | 225 | WebElement ele_StateDropDown = driver.findElementById("StateID"); 226 | 227 | Select slt_StateDropDown = new Select(ele_StateDropDown); 228 | 229 | slt_StateDropDown.selectByVisibleText("Tamil Nadu"); 230 | 231 | WebElement ele_CityeDropDown = driver.findElementById("CityID"); 232 | 233 | Select slt_CityeDropDown = new Select(ele_CityeDropDown); 234 | 235 | slt_CityeDropDown.selectByVisibleText("Chennai"); 236 | 237 | 238 | 239 | //15) Click Search 240 | //---------------- 241 | 242 | driver.findElementByXPath("//button[text()='Search']").click(); 243 | 244 | 245 | //16) Print all the 3 models and their prices 246 | //----------------------------------------- 247 | 248 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//table[@id='gvshow']//td[2]/following-sibling::td"))); 249 | 250 | Map map_Model_Price = new LinkedHashMap(); 251 | 252 | String strModel=""; 253 | String strPrice = ""; 254 | 255 | 256 | for(int i=1;i<=3;i++) 257 | { 258 | strModel = driver.findElementByXPath("//table[@id='gvshow']//tr["+i+"]//td[contains(text(),'ACTIVA')]").getText(); 259 | strPrice = driver.findElementByXPath("//table[@id='gvshow']//tr["+i+"]//td[contains(text(),'ACTIVA')]/following-sibling::td").getText(); 260 | 261 | map_Model_Price.put(strModel, strPrice); 262 | 263 | } 264 | 265 | System.out.println("|Model----------Price|"); 266 | 267 | for(Entry each:map_Model_Price.entrySet()) 268 | { 269 | System.out.print("|"+each.getKey()+"----------"+each.getValue()); 270 | System.out.println(); 271 | } 272 | 273 | driver.quit(); 274 | 275 | 276 | } 277 | 278 | } 279 | -------------------------------------------------------------------------------- /TestNaukri.java: -------------------------------------------------------------------------------- 1 | package SeleniumCoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.WebDriver; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.remote.DesiredCapabilities; 13 | 14 | public class TestNaukri { 15 | 16 | public static void main(String[] args) throws InterruptedException { 17 | // TODO Auto-generated method stub 18 | //Launching Chromebrowser 19 | System.setProperty("webdriver.chrome.driver", 20 | "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 21 | System.setProperty("webdriver.chrome.silentOutput", "true"); 22 | //To disable notifications 23 | ChromeDriver driver; 24 | ChromeOptions options= new ChromeOptions(); 25 | options.addArguments("--disable-notifications"); 26 | //DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 27 | DesiredCapabilities dc = new DesiredCapabilities(); 28 | 29 | options.addArguments("--incognito"); 30 | dc.setCapability(ChromeOptions.CAPABILITY, options); 31 | driver=new ChromeDriver(options); 32 | //Maximize the browser 33 | driver.manage().window().maximize(); 34 | //Load the url 35 | driver.get("https://www.naukri.com/"); 36 | //Implicitly wait for 5 milliseconds 37 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 38 | 39 | 40 | 41 | 42 | Set winSet = driver.getWindowHandles(); 43 | List winLis=new ArrayList(winSet); 44 | driver.switchTo().window(winLis.get(1)); 45 | driver.manage().window().maximize(); 46 | 47 | Thread.sleep(2000); 48 | 49 | 50 | String name1 = driver.findElementByXPath("//img[1]").getAttribute("alt"); 51 | System.out.println("Company name1 = "+name1); 52 | Thread.sleep(1000); 53 | driver.close(); 54 | Thread.sleep(2000); 55 | Set winSet1 = driver.getWindowHandles(); 56 | List winLis1=new ArrayList(winSet1); 57 | driver.switchTo().window(winLis1.get(1)); 58 | driver.manage().window().maximize(); 59 | 60 | 61 | 62 | 63 | String name2 = driver.findElementByXPath("//img[1]").getAttribute("alt"); 64 | System.out.println("Company name2 = "+name2); 65 | driver.close(); 66 | Thread.sleep(2000); 67 | 68 | 69 | Set winSet2 = driver.getWindowHandles(); 70 | List winLis2=new ArrayList(winSet2); 71 | driver.switchTo().window(winLis2.get(0)); 72 | 73 | WebElement fileupload = driver.findElementById("file_upload"); 74 | fileupload.sendKeys("/Users/kumanananitha/Downloads/Anitha.jpeg"); 75 | Thread.sleep(1000); 76 | String msg =driver.findElementByXPath("//div[@class='error-header-desc error']").getText(); 77 | System.out.println("The error message is :" +msg); 78 | driver.close(); 79 | 80 | 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /Zalando.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.Alert; 9 | import org.openqa.selenium.JavascriptExecutor; 10 | import org.openqa.selenium.Keys; 11 | import org.openqa.selenium.NoAlertPresentException; 12 | import org.openqa.selenium.UnexpectedAlertBehaviour; 13 | import org.openqa.selenium.WebDriver.Window; 14 | import org.openqa.selenium.WebElement; 15 | import org.openqa.selenium.chrome.ChromeDriver; 16 | import org.openqa.selenium.chrome.ChromeOptions; 17 | import org.openqa.selenium.interactions.Actions; 18 | import org.openqa.selenium.remote.CapabilityType; 19 | import org.openqa.selenium.remote.DesiredCapabilities; 20 | import org.openqa.selenium.support.ui.ExpectedConditions; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | 23 | public class Zalando { 24 | 25 | public static void main(String[] args) throws InterruptedException { 26 | // TODO Auto-generated method stub 27 | // 1) Go to https://www.zalando.com/ 28 | System.setProperty("webdriver.chrome.silentOutput", "true"); 29 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 30 | // disable the notifications 31 | ChromeOptions options = new ChromeOptions(); 32 | options.addArguments("--disable-notifications"); 33 | // Launching Chrome Browser 34 | ChromeDriver driver = new ChromeDriver(options); 35 | // To Load the url 36 | driver.get("https://www.zalando.com/"); 37 | // To maximize the browser 38 | try 39 | { 40 | System.out.println("alert present"); 41 | 42 | Alert alert=driver.switchTo().alert(); 43 | String alerttext=alert.getText(); 44 | System.out.println("The alert message is"+alerttext); 45 | alert.accept(); 46 | 47 | //return true; 48 | } // try 49 | catch (NoAlertPresentException Ex) 50 | { 51 | System.out.println("Alert not present"); 52 | // return false; 53 | } // catch 54 | 55 | 56 | driver.manage().window().maximize(); 57 | // implicitly wait 58 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 59 | WebDriverWait wait = new WebDriverWait(driver, 30); 60 | JavascriptExecutor js = (JavascriptExecutor) driver; 61 | Actions action=new Actions(driver); 62 | 63 | //Thread.sleep(2000); 64 | 65 | 66 | 67 | 68 | //WebDriverWait wait = new WebDriverWait(driver, 300 /*timeout in seconds*/); 69 | /*if(wait.until(ExpectedConditions.alertIsPresent())!=null) 70 | { 71 | System.out.println("alert present"); 72 | Alert alert=driver.switchTo().alert(); 73 | String alerttext=alert.getText(); 74 | System.out.println("The alert message is"+alerttext); 75 | alert.accept(); 76 | } 77 | 78 | else 79 | System.out.println("alert not present"); 80 | */ 81 | // 2) Get the Alert text and print it 82 | Thread.sleep(500); 83 | // 3) Close the Alert box and click on Zalando.uk 84 | driver.findElementByXPath("//a[text()='Zalando.uk']").click(); 85 | Thread.sleep(500); 86 | // 4) Click Women--> Clothing and click Coat 87 | driver.findElementByXPath("(//span[contains(@class,'z-text z-navicat-header_genderText')])[1]").click(); 88 | driver.findElementByXPath("(//span[text()='Clothing'])[1]").click(); 89 | Thread.sleep(500); 90 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//a[@href='/womens-clothing-coats/'])[2]"))); 91 | driver.findElementByXPath("(//a[@href='/womens-clothing-coats/'])[2]").click(); 92 | Thread.sleep(1000); 93 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//button[@class='uc-btn uc-btn-primary']"))); 94 | // driver.findElementByXPath("//button[contains(text(),'That’s OK')]").click(); 95 | driver.findElementByXPath("//button[@class='uc-btn uc-btn-primary']").click(); 96 | 97 | // 5) Choose Material as cotton (100%) and Length as thigh-length 98 | driver.findElementByXPath("//span[@data-label='Material']//span[1]").click(); 99 | driver.findElementByXPath("//span[text()='cotton (100%)']").click(); 100 | driver.findElementByXPath("//button[text()='Save']").click(); 101 | Thread.sleep(1000); 102 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[@data-label='Length']//span[1]"))); 103 | driver.findElementByXPath("//span[@data-label='Length']//span[1]").click(); 104 | driver.findElementByXPath("//span[text()='thigh-length']").click(); 105 | driver.findElementByXPath("//button[text()='Save']").click(); 106 | // 6) Click on Q/S designed by MANTEL - Parka coat 107 | Thread.sleep(1000); 108 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//img[@alt='MANTEL - Parka - navy']"))); 109 | driver.findElementByXPath("//img[@alt='MANTEL - Parka - navy']").click(); 110 | Thread.sleep(1000); 111 | // 7) Check the availability for Color as Olive and Size as 'M' 112 | driver.findElementByXPath("(//img[@alt='olive'])[2]").click(); 113 | driver.findElementByXPath("//button[@id='picker-trigger']//span[1]").click(); 114 | driver.findElementByXPath("(//li[@role='option']//div)[5]").click(); 115 | String availability = driver.findElementByXPath("//h2[contains(@class,'A95iT1 pDVUjz')]").getText(); 116 | System.out.println("Avaialability of stock"+availability); 117 | // 8) If the previous preference is not available, check availability for Color Navy and Size 'M' 118 | if(availability.equalsIgnoreCase("Out of stock")) 119 | { 120 | driver.findElementByXPath("(//img[@alt='navy'])[2]").click(); 121 | driver.findElementByXPath("//button[@id='picker-trigger']//span[1]").click(); 122 | driver.findElementByXPath("(//li[@role='option']//div)[5]").click(); 123 | String free=driver.findElementByXPath("(//span[text()='Free'])[1]").getText(); 124 | System.out.println("The standard delivery is"+free); 125 | // 9) Add to bag only if Standard Delivery is free 126 | 127 | if(free.equalsIgnoreCase("Free")) 128 | { driver.findElementByXPath("//span[text()='Add to bag']").click(); 129 | // 10) Mouse over on Your Bag and Click on "Go to Bag" 130 | WebElement bag=driver.findElementByXPath("//a[@href='/cart/']"); 131 | action.moveToElement(bag).build().perform(); 132 | driver.findElementByXPath("//div[text()='Go to bag']").click(); 133 | // 11) Capture the Estimated Deliver Date and print 134 | 135 | String estddate=driver.findElementByXPath("(//span[contains(@class,'z-2-text z-2-text-body')])[1]").getText(); 136 | System.out.println("The estimated delivery date and time is"+estddate); 137 | } 138 | } 139 | 140 | // 12) Mouse over on FREE DELIVERY & RETURNS*, get the tool tip text and print 141 | WebElement freedelret=driver.findElementByXPath("(//a[@name='“headbanner.about.us\"'])[1]"); 142 | action.moveToElement(freedelret).build().perform(); 143 | String tooltiptxt= driver.findElementByXPath("(//span[@class='z-navicat-header-uspBar_message-split_styled'])[2]").getAttribute("title"); 144 | System.out.println("The tooltip text is"+tooltiptxt); 145 | // 13) Click on FREE DELIVERY & RETURNS 146 | freedelret.click(); 147 | // 14) Click on Start chat in the Start chat and go to the new window 148 | Thread.sleep(3000); 149 | 150 | // 14) Click on Start chat in the Start chat and go to the new window 151 | if (driver.findElementByXPath("//span[text()='Start chat']").isEnabled() == true) { 152 | driver.findElementByXPath("//span[text()='Start chat']").click(); 153 | } else { 154 | System.out.println("The chat box not enabled"); 155 | } 156 | Set windowHandles = driver.getWindowHandles(); 157 | 158 | List lstwindowHandles = new ArrayList(windowHandles); 159 | 160 | driver.switchTo().window(lstwindowHandles.get(1)); 161 | 162 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 163 | 164 | // wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[contains(text(),'Start chat')]"))); 165 | // driver.findElementByXPath("//span[contains(text(),'Start chat')]").click(); 166 | // Set winset=driver.getWindowHandles(); 167 | // List winlist=new ArrayList (winset); 168 | // driver.switchTo().window(winlist.get(1)); 169 | //// 15) Enter you first name and a dummy email and click Start Chat 170 | 171 | driver.findElementById("prechat_customer_name_id").sendKeys("Anitha",Keys.ENTER); 172 | driver.findElementById("prechat_customer_email_id").sendKeys("anitha@anitha.com"); 173 | driver.findElementById("prechat_submit").click(); 174 | Thread.sleep(3000); 175 | // 16) Type Hi, click Send and print thr reply message and close the chat window. 176 | 177 | driver.findElementById("liveAgentChatTextArea").sendKeys("Hi"); 178 | driver.findElementByXPath("//button[text()='Send']").click(); 179 | Thread.sleep(500); 180 | String replymssg=driver.findElementByXPath("(//span[@class='messageText'])[4]").getText(); 181 | System.out.println("the reply message is"+replymssg); 182 | 183 | 184 | } 185 | 186 | } 187 | -------------------------------------------------------------------------------- /airbnb.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Map.Entry; 8 | import java.util.Set; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import org.openqa.selenium.JavascriptExecutor; 12 | import org.openqa.selenium.Keys; 13 | import org.openqa.selenium.UnexpectedAlertBehaviour; 14 | import org.openqa.selenium.WebElement; 15 | import org.openqa.selenium.chrome.ChromeDriver; 16 | import org.openqa.selenium.chrome.ChromeOptions; 17 | import org.openqa.selenium.interactions.Actions; 18 | import org.openqa.selenium.remote.CapabilityType; 19 | import org.openqa.selenium.remote.DesiredCapabilities; 20 | import org.openqa.selenium.support.ui.ExpectedConditions; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | 23 | public class airbnb { 24 | 25 | public static void main(String[] args) throws InterruptedException { 26 | // TODO Auto-generated method stub 27 | // 1) Go to https://www.airbnb.co.in/ 28 | System.setProperty("webdriver.chrome.silentOutput", "true"); 29 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 30 | // disable the notifications 31 | ChromeOptions options = new ChromeOptions(); 32 | options.addArguments("--disable-notifications"); 33 | DesiredCapabilities cap = new DesiredCapabilities(); 34 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 35 | options.merge(cap); 36 | // Launching Chrome Browser 37 | ChromeDriver driver = new ChromeDriver(options); 38 | // To Load the url 39 | driver.get("https://www.airbnb.co.in/"); 40 | // To maximize the browser 41 | driver.manage().window().maximize(); 42 | // implicitly wait 43 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 44 | WebDriverWait wait = new WebDriverWait(driver, 10); 45 | JavascriptExecutor js = (JavascriptExecutor) driver; 46 | Actions action=new Actions(driver); 47 | Thread.sleep(1000); 48 | //close the cookie button 49 | driver.findElementByXPath("//button[@title='OK']").click(); 50 | // 2) Type Coorg in location and Select Coorg, Karnataka 51 | driver.findElementById("bigsearch-query-attached-query").sendKeys("Coorg"); 52 | driver.findElementByXPath("//div[text()='Coorg, Karnataka']").click(); 53 | // 3) Select the Start Date as June 1st and End Date as June 5th 54 | WebElement dates= driver.findElementByXPath("//div[text()='Add dates']"); 55 | dates.click(); 56 | Thread.sleep(1000); 57 | dates.click(); 58 | 59 | driver.findElementByXPath("(//table[@class='_cvkwaj']/following::table)[2]/tbody[1]/tr[1]/td[2]/div[1]/div[1]").click(); 60 | driver.findElementByXPath("(//table[@class='_cvkwaj']/following::table)[2]/tbody[1]/tr[1]/td[6]/div[1]/div[1]").click(); 61 | // 4) Select guests as 6 adults, 3 child and Click Search 62 | driver.findElementByXPath("//div[text()='Add guests']").click(); 63 | WebElement adults=driver.findElementByXPath("(//button[@aria-label='increase value'])[1]"); 64 | adults.click(); 65 | adults.click(); 66 | adults.click(); 67 | adults.click(); 68 | adults.click(); 69 | adults.click(); 70 | WebElement children=driver.findElementByXPath("(//button[@aria-label='increase value'])[2]"); 71 | children.click(); 72 | children.click(); 73 | children.click(); 74 | driver.findElementByXPath("//span[@class='_m9v25n']").click(); 75 | // 5) Click Cancellation flexibility and enable the filter and Save 76 | driver.findElementByXPath("(//span[text()='Cancellation flexibility'])[1]").click(); 77 | driver.findElementByClassName("_6ndphef").click(); 78 | driver.findElementById("filter-panel-save-button").click(); 79 | Thread.sleep(500); 80 | // 6) Select Type of Place as Entire Place and Save 81 | driver.findElementByXPath("(//span[text()='Type of place'])[1]").click(); 82 | driver.findElementByXPath("(//span[@data-checkbox='true'])[1]").click(); 83 | driver.findElementById("filter-panel-save-button").click(); 84 | Thread.sleep(500); 85 | // 7) Set Min price as 3000 and max price as 5000 86 | driver.findElementByXPath("//div[@id='menuItemButton-price_range']//button[1]").click(); 87 | Thread.sleep(500); 88 | WebElement minprice= driver.findElementByXPath("//input[@id='price_filter_min']"); 89 | minprice.click(); 90 | Thread.sleep(1000); 91 | // minprice.sendKeys(Keys.CONTROL, Keys.chord("a")); //select all text in textbox 92 | // minprice.sendKeys(Keys.BACK_SPACE); //delete it 93 | minprice.sendKeys(Keys.HOME, Keys.chord(Keys.SHIFT, Keys.END),"3000"); 94 | Thread.sleep(500); 95 | 96 | WebElement maxprice=driver.findElementByXPath("//input[@id='price_filter_max']"); 97 | maxprice.click(); 98 | Thread.sleep(1000); 99 | // maxprice.sendKeys(Keys.CONTROL, Keys.chord("a")); //select all text in textbox 100 | // maxprice.sendKeys(Keys.BACK_SPACE); //delete it 101 | 102 | maxprice.sendKeys(Keys.HOME, Keys.chord(Keys.SHIFT, Keys.END),"5000"); 103 | Thread.sleep(1000); 104 | driver.findElementById("filter-panel-save-button").click(); 105 | Thread.sleep(1000); 106 | // 8) Click More Filters and set 3 Bedrooms and 3 Bathrooms 107 | driver.findElementByXPath("(//span[text()='More filters'])[1]").click(); 108 | WebElement bedrooms=driver.findElementByXPath("(//div[@id='filterItem-stepper-min_bedrooms-0']//button)[2]"); 109 | Thread.sleep(500); 110 | bedrooms.click(); 111 | bedrooms.click(); 112 | bedrooms.click(); 113 | WebElement bathrooms=driver.findElementByXPath("//div[@id='filterItem-stepper-min_bathrooms-0']//button[2]"); 114 | Thread.sleep(500); 115 | bathrooms.click(); 116 | bathrooms.click(); 117 | bathrooms.click(); 118 | // 9) Check the Amenities with Kitchen, Facilities with Free parking on premisses, Property as House and Host Language as English 119 | // and click on Stays only when stays available 120 | Thread.sleep(1000); 121 | //kitchen 122 | driver.findElementByXPath("//input[@name='Kitchen']/following-sibling::span[1]").click(); 123 | //facilities with free parking 124 | Thread.sleep(500); 125 | driver.findElementByXPath("//input[@name='Free parking on premises']/following-sibling::span[1]").click(); 126 | //property as house 127 | Thread.sleep(500); 128 | driver.findElementByXPath("//input[@name='House']/following-sibling::span[1]").click(); 129 | //click on stays as 130 | Thread.sleep(500); 131 | driver.findElementByXPath("//div[@class='_6s3rid']/following-sibling::button[1]").click(); 132 | Thread.sleep(3000); 133 | // 10) Click Prahari Nivas, the complete house 134 | driver.findElementByClassName("_15tommw").click(); 135 | // 11) Click on "Show all * amenities" 136 | Set winset=driver.getWindowHandles(); 137 | List winlist=new ArrayList (winset); 138 | driver.switchTo().window(winlist.get(1)); 139 | Thread.sleep(1000); 140 | WebElement showamenities= driver.findElementByXPath("(//div[@class='_1p3joamp']//button)[1]"); 141 | wait.until(ExpectedConditions.elementToBeClickable(showamenities)); 142 | 143 | js.executeScript("arguments[0].click()",showamenities); 144 | Thread.sleep(2000); 145 | 146 | // 12) Print all the Not included amenities 147 | List not_amenities=driver.findElementsByXPath("(//div[@class='_ylytgbo']//del)"); 148 | int i=not_amenities.size(); 149 | System.out.println("the total num of non amenities are "+ i); 150 | for(WebElement eachna:not_amenities) 151 | {System.out.println("Non amenties are "+ eachna.getText());} 152 | driver.findElementByXPath("(//button[@aria-label='Close'])[2]//span").click(); 153 | Thread.sleep(2000); 154 | // (//div[@class='_ylytgbo']//del)[5] 155 | // 13) Verify the Check-in date, Check-out date and Guests 156 | // 14) Read all the Sleeping arrangements and Print 157 | List sleep_arrange=driver.findElementsByXPath("(//div[@class='_1p3joamp']/following-sibling::div)"); 158 | int j=sleep_arrange.size(); 159 | System.out.println("The total num of sleep arrangements are "+ j); 160 | driver.findElementByXPath("//div[contains(text(),'Bed')]/ancestor::div//div[@class='_1mlprnc']").click(); 161 | driver.findElementByXPath("(//div[contains(text(),'Bed')]/ancestor::div//div[@class='_1mlprnc'])[2]").click(); 162 | //for printing sleeping arrangements 163 | for(int k=0;k eleBedrooms = driver.findElementsByXPath("//div[contains(text(),'Bedroom')]"); 174 | // List eleBeds = driver.findElementsByXPath("//div[contains(text(),'bed')]"); 175 | // Map map=new LinkedHashMap(); 176 | // Thread.sleep(1000); 177 | // WebElement eleNext = driver.findElementByXPath("//div[@data-plugin-in-point-id='SLEEPING_ARRANGEMENT_DEFAULT']//*[contains(@style,'right')]//button"); 178 | // int j=0; 179 | // try 180 | // { 181 | // while(j==0) 182 | // { 183 | // if(eleNext.isDisplayed()) 184 | // { 185 | // for(int k=0;i eachEntry:map.entrySet()) 205 | // { 206 | // System.out.println(eachEntry.getKey()+"-->"+eachEntry.getValue()); 207 | // } 208 | */ 209 | //15) Close all the browsers 210 | 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /ajio.java: -------------------------------------------------------------------------------- 1 | package Javacoding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.JavascriptExecutor; 9 | import org.openqa.selenium.Keys; 10 | import org.openqa.selenium.UnexpectedAlertBehaviour; 11 | import org.openqa.selenium.WebElement; 12 | import org.openqa.selenium.chrome.ChromeDriver; 13 | import org.openqa.selenium.chrome.ChromeOptions; 14 | import org.openqa.selenium.interactions.Actions; 15 | import org.openqa.selenium.remote.CapabilityType; 16 | import org.openqa.selenium.remote.DesiredCapabilities; 17 | import org.openqa.selenium.support.ui.ExpectedConditions; 18 | import org.openqa.selenium.support.ui.Select; 19 | import org.openqa.selenium.support.ui.WebDriverWait; 20 | 21 | public class ajio { 22 | 23 | public static void main(String[] args) throws InterruptedException { 24 | // 1)Go to https://www.ajio.com/ 25 | // TODO Auto-generated method stub 26 | System.setProperty("webdriver.chrome.silentOutput", "true"); 27 | System.setProperty("webdriver.chrome.driver", "/Users/kumanananitha/eclipse-workspace/Selenium/drivers/chromedriver"); 28 | // disable the notifications 29 | ChromeOptions options = new ChromeOptions(); 30 | options.addArguments("--disable-notifications"); 31 | 32 | DesiredCapabilities cap = new DesiredCapabilities(); 33 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 34 | options.merge(cap); 35 | // Launching Chrome Browser 36 | ChromeDriver driver = new ChromeDriver(options); 37 | // To Load the url 38 | driver.get("https://www.ajio.com/shop/sale"); 39 | // To maximize the browser 40 | driver.manage().window().maximize(); 41 | // implicitly wait 42 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 43 | WebDriverWait wait = new WebDriverWait(driver, 10); 44 | JavascriptExecutor js = (JavascriptExecutor) driver; 45 | Actions action=new Actions(driver); 46 | // 2) Enter Bags in the Search field and Select Bags in Women Handbags 47 | driver.findElementByName("searchVal").sendKeys("Bags"); 48 | Thread.sleep(500); 49 | driver.findElementByXPath("(//span[text()='Women Handbags'])[1]").click(); 50 | Thread.sleep(1000); 51 | // 3) Click on five grid and Select SORT BY as "What's New" 52 | driver.findElementByClassName("five-grid").click(); 53 | Thread.sleep(500); 54 | WebElement dropdown = driver.findElementByXPath("//div[@class='filter-dropdown']//select[1]"); 55 | Select option=new Select(dropdown); 56 | option.selectByVisibleText("What's New"); 57 | Thread.sleep(1000); 58 | // 4) Enter Price Range Min as 2000 and Max as 5000 59 | driver.findElementByXPath("//span[text()='price']").click(); 60 | driver.findElementById("minPrice").sendKeys("2500"); 61 | driver.findElementById("maxPrice").sendKeys("5000"); 62 | driver.findElementByXPath("//button[@class='rilrtl-button ic-toparw']").click(); 63 | Thread.sleep(500); 64 | // 5) Click on thefive-gridproduct "Puma Ferrari LS Shoulder Bag" 65 | driver.findElementByXPath("//div[text()='Ferrari LS Shoulder Bag']").click(); 66 | Set winset=driver.getWindowHandles(); 67 | List winlist=new ArrayList (winset); 68 | driver.switchTo().window(winlist.get(1)); 69 | 70 | // 6) Verify the Coupon code for the price above 2690 is applicable for your product, 71 | //if applicable the get the Coupon Code and Calculate the discount price for the coupon 72 | String coupondesc=driver.findElementByClassName("promo-desc").getText(); 73 | 74 | 75 | String prodprice=driver.findElementByClassName("prod-sp").getText(); 76 | int productprice=Integer.parseInt(prodprice.replaceAll("\\D","")); 77 | 78 | String afterdiscprice=driver.findElementByXPath("//div[@class='promo-discounted-price']//span[1]").getText(); 79 | int discountprice=Integer.parseInt(afterdiscprice.replaceAll("\\D","")); 80 | // if(productprice>2690) 81 | // { 82 | float discamt=productprice-discountprice; 83 | 84 | System.out.println("the discounted amount is " +discamt); 85 | //} 86 | // 7) Check the availability of the product for pincode 560043, 87 | //print the expected delivery date if it is available 88 | driver.findElementByXPath("//span[@class='edd-pincode-msg-details edd-pincode-msg-details-pointer edd-pincode-msg-details-text-color']").click(); 89 | driver.findElementByName("pincode").sendKeys("607807"); 90 | driver.findElementByClassName("edd-pincode-modal-submit-btn").click(); 91 | 92 | WebElement successpincode=driver.findElementByClassName("edd-message-success-pincode"); 93 | if(successpincode!=null) 94 | { String deldate=driver.findElementByClassName("edd-message-success-details-highlighted").getText();} 95 | else {System.out.println("the product not available in pincode");} 96 | // 8) Click on Other Informations under Product Details 97 | //and Print the Customer Care address, phone and email 98 | driver.findElementByXPath("//div[text()='Other information']").click(); 99 | Thread.sleep(1000); 100 | String addremail=driver.findElementByXPath("//span[text()='Customer Care Address']/following-sibling::span[2]").getText(); 101 | System.out.println("the addr,email,phnumber " + addremail); 102 | Thread.sleep(500); 103 | // 9) Click on ADD TO BAG and then GO TO BAG 104 | WebElement addtobag=driver.findElementByClassName("btn-gold"); 105 | js.executeScript("arguments[0].click()",addtobag); 106 | Thread.sleep(4000); 107 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@class='btn-cart']"))); 108 | ////span[@class='ic-pdp-add-cart']/following-sibling::span 109 | WebElement gotobag=driver.findElementByXPath("//div[@class='btn-cart']"); 110 | if (gotobag.isEnabled()) 111 | js.executeScript("arguments[0].click()", gotobag); 112 | Thread.sleep(2000); 113 | 114 | // 10) Check the Order Total before apply coupon 115 | String ordertotal=driver.findElementByXPath("//span[@class='price-value bold-font']").getText(); 116 | int ordtotal=Integer.parseInt(ordertotal.replaceAll("\\D","")); 117 | // 11) Enter Coup.on Code and Click Apply 118 | driver.findElementById("couponCodeInput").sendKeys("EPIC"); 119 | driver.findElementByXPath("//button[text()='Apply']").click(); 120 | Thread.sleep(1000); 121 | // 12) Verify the Coupon Savings amount(round off if it in decimal) under Order Summary 122 | //and the matches the amount calculated in Product details 123 | String savamt=driver.findElementByXPath("(//span[@class='price-value discount-price'])[2]").getText(); 124 | System.out.println("the savings amount "+savamt); 125 | String arrOfStr = savamt.substring(4); 126 | System.out.println(arrOfStr); 127 | //System.out.println(arrOfStr[1]); 128 | float savingamt=Float.parseFloat(arrOfStr.replaceAll("[^0-9.]","")); 129 | System.out.println("After reg ex applied "+savingamt); 130 | float savingsamt=Math.round(savingamt); 131 | if(savingsamt==discamt) 132 | {System.out.println("The discount amount matches"); } 133 | else 134 | System.out.println("The amount doesnot match"); 135 | Thread.sleep(1000); 136 | // 13) Click on Delete and Delete the item from Bag 137 | driver.findElementByClassName("delete-btn").click(); 138 | Thread.sleep(500); 139 | driver.findElementByXPath("(//div[@class='delete-btn'])[2]").click(); 140 | // 14) Close all the browsers 141 | 142 | } 143 | 144 | } 145 | 146 | --------------------------------------------------------------------------------