├── Airbnb.java ├── BigBasket.java ├── CRM.java ├── Carwale.java ├── Honda.java ├── HpProgram.java ├── JustDial2.java ├── MakeMyTrip.java ├── Myntra.java ├── Nykka.java ├── PepperFry.java ├── README.md ├── Shiksha.java ├── SnapDeal.java ├── Zalando.java ├── output.xlsx └── snap1.png /Airbnb.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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.Set; 8 | import java.util.Map.Entry; 9 | import java.util.NoSuchElementException; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import org.openqa.selenium.JavascriptExecutor; 13 | import org.openqa.selenium.Keys; 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.DesiredCapabilities; 19 | import org.openqa.selenium.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.WebDriverWait; 21 | 22 | public class Airbnb { 23 | 24 | public static void main(String[] args) throws InterruptedException { 25 | System.setProperty("webdriver.chrome.silentOutput", "true"); 26 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 27 | // disable the notifications 28 | 29 | ChromeOptions options = new ChromeOptions(); 30 | options.addArguments("--disable-notifications"); 31 | DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 32 | 33 | options.addArguments("--incognito"); 34 | capabilities.setCapability(ChromeOptions.CAPABILITY, options); 35 | // Launching Chrome Browser 36 | ChromeDriver driver = new ChromeDriver(options); 37 | // To maximize the browser 38 | driver.manage().window().maximize(); 39 | 40 | // implicitly wait 41 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 42 | WebDriverWait wait = new WebDriverWait(driver, 30); 43 | JavascriptExecutor js = (JavascriptExecutor) driver; 44 | Actions actions = new Actions(driver); 45 | 46 | // 1) Go to https://www.airbnb.co.in/ 47 | driver.get("https://www.airbnb.co.in/"); 48 | Thread.sleep(3000); 49 | WebElement eleBtnOk = driver.findElementByXPath("//button[@class='optanon-allow-all accept-cookies-button']"); 50 | js.executeScript("arguments[0].click()", eleBtnOk); 51 | 52 | // 2) Type Coorg in location and Select Coorg, Karnataka 53 | driver.findElementByXPath("//input[@id='bigsearch-query-attached-query']").sendKeys("Coorg"); 54 | driver.findElementByXPath("//div[text()='Coorg, Karnataka']").click(); 55 | Thread.sleep(2000); 56 | // 3) Select the Start Date as June 1st and End Date as June 5th 57 | driver.findElementByXPath("(//div[text()='June 2020']/following::div[contains(text(),'1')])[1]").click(); 58 | driver.findElementByXPath("(//div[text()='June 2020']/following::div[contains(text(),'5')])[1]").click(); 59 | 60 | // 4) Select guests as 6 adults, 3 child and Click Search 61 | driver.findElementByXPath("//div[text()='Add guests']").click(); 62 | for (int i = 0; i < 6; i++) { 63 | driver.findElementByXPath("(//button[@aria-label='increase value'])[1]").click(); 64 | } 65 | for (int i = 0; i < 3; i++) { 66 | driver.findElementByXPath("(//button[@aria-label='increase value'])[2]").click(); 67 | } 68 | WebElement eleSearch = driver.findElementByXPath("//span[text()='Search']"); 69 | js.executeScript("arguments[0].click()", eleSearch); 70 | 71 | Thread.sleep(3000); 72 | 73 | // 5) Click Cancellation flexibility and enable the filter and Save 74 | driver.findElementByXPath("(//span[text()='Cancellation flexibility'])[1]").click(); 75 | driver.findElementByXPath("//button[@id='filterItem-switch-flexible_cancellation-true']").click(); 76 | driver.findElementByXPath("//button[@id='filter-panel-save-button']").click(); 77 | Thread.sleep(3000); 78 | 79 | // 6) Select Type of Place as Entire Place and Save 80 | driver.findElementByXPath("(//span[text()='Type of place'])[1]").click(); 81 | driver.findElementByXPath("//div[text()='Entire place']").click(); 82 | driver.findElementByXPath("//button[@id='filter-panel-save-button']").click(); 83 | Thread.sleep(3000); 84 | 85 | // 7) Set Min price as 3000 and max price as 5000 86 | driver.findElementByXPath("(//span[text()='Price'])[1]").click(); 87 | Thread.sleep(500); 88 | WebElement eleMinPrice = driver.findElementByXPath("//div[@class='_fywymp7']/input[@id='price_filter_min']"); 89 | actions.doubleClick(eleMinPrice).perform(); 90 | // eleMinPrice.clear(); 91 | eleMinPrice.sendKeys("3000"); 92 | Thread.sleep(500); 93 | WebElement eleMaxPrice = driver.findElementByXPath("//div[@class='_fywymp7']/input[@id='price_filter_max']"); 94 | // actions.doubleClick().perform(); 95 | // actions.doubleClick(eleMaxPrice).perform(); 96 | String maxPrice = eleMaxPrice.getAttribute("value"); 97 | // System.out.println(maxPrice); 98 | int maxPriceLen = maxPrice.length(); 99 | // System.out.println(maxPriceLen); 100 | for (int j = 0; j < maxPriceLen; j++) { 101 | eleMaxPrice.sendKeys(Keys.BACK_SPACE); 102 | } 103 | eleMaxPrice.sendKeys("5000"); 104 | driver.findElementByXPath("//button[@id='filter-panel-save-button']").click(); 105 | Thread.sleep(3000); 106 | 107 | // 8) Click More Filters and set 3 Bedrooms and 3 Bathrooms 108 | driver.findElementByXPath("(//span[text()='More filters'])[1]").click(); 109 | Thread.sleep(500); 110 | for (int k = 0; k < 3; k++) { 111 | driver.findElementByXPath("(//button[@aria-label='increase value'])[2]").click(); 112 | driver.findElementByXPath("(//button[@aria-label='increase value'])[3]").click(); 113 | } 114 | 115 | // 9) Check the Amenities with Kitchen, Facilities with Free parking on premisses, Property as House and Host Language as English 116 | // and click on Stays only when stays available 117 | driver.findElementByXPath("//div[text()='Kitchen']").click(); 118 | driver.findElementByXPath("//div[text()='Free parking on premises']").click(); 119 | driver.findElementByXPath("//div[text()='House']").click(); 120 | driver.findElementByXPath("//div[text()='English']").click(); 121 | String btnText = driver.findElementByXPath("//button[@class='_2i58o3a']").getText(); 122 | // System.out.println(btnText); 123 | String repBtnText = btnText.replaceAll("[^0-9]", ""); 124 | // System.out.println(repBtnText); 125 | int intBtnText = Integer.parseInt(repBtnText); 126 | if (intBtnText > 0) { 127 | driver.findElementByXPath("//button[@class='_2i58o3a']").click(); 128 | } 129 | String strDate = driver.findElementByXPath("(//button[@class='_37g0dr4'])[2]").getText(); 130 | String strGuests = driver.findElementByXPath("(//button[@class='_37g0dr4'])[3]").getText(); 131 | // System.out.println("The date choosed for vacation is :"+strDate); 132 | // System.out.println("no of guests : "+strGuests); 133 | Thread.sleep(1000); 134 | // 10) Click Prahari Nivas, the complete house 135 | WebElement elePrahari = driver.findElementByXPath("(//a[@aria-label='Prahari Nivas, the complete house'])[1]"); 136 | js.executeScript("arguments[0].click()", elePrahari); 137 | 138 | Set allWindows = driver.getWindowHandles(); 139 | List allLists = new ArrayList(allWindows); 140 | driver.switchTo().window(allLists.get(1)); 141 | Thread.sleep(10000); 142 | driver.executeScript("window.scrollBy(0, 1230)"); 143 | // 11) Click on "Show all * amenities" 144 | WebElement eleShowAll = driver.findElementByXPath("//button[contains(text(),'Show all') and contains(text(),'amenities')]"); 145 | //wait.until( 146 | // ExpectedConditions.visibilityOf(driver.findElementByXPath("//[contains(text(),'Show all') and contains(text(),'amenities')]"))); 147 | js.executeScript("arguments[0].click()", eleShowAll); 148 | 149 | Thread.sleep(2000); 150 | 151 | // 12) Print all the Not included amenities 152 | System.out.println("The Not included amenities are below: "); 153 | List lstNonAmenities = driver.findElementsByXPath("//div[text()='Not included']//following::del"); 154 | int sizeLstNonAmenities = lstNonAmenities.size(); 155 | for (int a = 0; a < sizeLstNonAmenities; a++) { 156 | String allNonAmenities = lstNonAmenities.get(a).getText(); 157 | System.out.println(allNonAmenities); 158 | } 159 | driver.findElementByXPath("//div[@aria-label='Amenities']//button[@aria-label='Close']").click(); 160 | // 13) Verify the Check-in date, Check-out date and Guests 161 | String strCheckinDate = driver.findElementByXPath("//input[@id='checkin']").getAttribute("value"); 162 | String strCheckoutDate = driver.findElementByXPath("//input[@id='checkout']").getAttribute("value"); 163 | String strGuest = driver.findElementByXPath("//span[@class='guest-label__text guest-label__text-guests']") 164 | .getText(); 165 | if (strCheckinDate.equalsIgnoreCase("2020-06-01") && strCheckoutDate.equalsIgnoreCase("2020-06-05")) { 166 | System.out.println("The Checkin date is : " + strCheckinDate); 167 | System.out.println("The Checkout date is : " + strCheckoutDate); 168 | } 169 | if (strGuest.equalsIgnoreCase("9 guests")) { 170 | System.out.println("The No of guests are :" + strGuest); 171 | } 172 | // 14) Read all the Sleeping arrangements and Print 173 | Map maps = new LinkedHashMap(); 174 | List lstBedrooms = driver 175 | .findElementsByXPath("//div[@class='_7y0rt79']//following-sibling::div[@class='_1p3joamp']"); 176 | List lstBeds = driver 177 | .findElementsByXPath("//div[@class='_7y0rt79']//following-sibling::div[@class='_czm8crp']"); 178 | int bedroomsSize = lstBedrooms.size(); 179 | for (int k = 0; k < bedroomsSize; k++) { 180 | String mapOverview = lstBedrooms.get(k).getText(); 181 | String mapFeatures = lstBeds.get(k).getText(); 182 | maps.put(mapOverview, mapFeatures); 183 | } 184 | // for (Entry each : maps.entrySet()) { 185 | // System.out.println(each.getKey() + " ---------- " + each.getValue()); 186 | // 187 | // } 188 | for (int b=0;b<2;b++) { 189 | driver.findElementByXPath("//div[@class='_1mlprnc' and contains(@style,'right')]").click(); 190 | } 191 | Thread.sleep(2000); 192 | 193 | // for (int b=1; b<=100; b++) { 194 | // try { 195 | // if(driver.findElementByXPath("//div[@class='_1mlprnc' and contains(@style,'right')]").isEnabled()){ 196 | // driver.findElementByXPath("//div[@class='_1mlprnc' and contains(@style,'right')]").click(); 197 | // 198 | // }else { 199 | // break; 200 | // } 201 | // } 202 | // catch(NoSuchElementException e) { 203 | // break; 204 | // } 205 | // } 206 | // Thread.sleep(2000); 207 | List lstBedrooms1 = driver 208 | .findElementsByXPath("//div[@class='_7y0rt79']//following-sibling::div[@class='_1p3joamp']"); 209 | List lstBeds1 = driver 210 | .findElementsByXPath("//div[@class='_7y0rt79']//following-sibling::div[@class='_czm8crp']"); 211 | int bedroomsSize1 = lstBedrooms1.size(); 212 | for (int k = 0; k < bedroomsSize1; k++) { 213 | String mapOverview1 = lstBedrooms1.get(k).getText(); 214 | String mapFeatures1 = lstBeds1.get(k).getText(); 215 | maps.put(mapOverview1, mapFeatures1); 216 | } 217 | 218 | //System.out.println(maps); 219 | for (Entry each : maps.entrySet()) { 220 | System.out.println(each.getKey() + " ---------- " + each.getValue()); 221 | 222 | } 223 | 224 | // 15) Close all the browsers 225 | driver.quit(); 226 | 227 | } 228 | 229 | } 230 | 231 | -------------------------------------------------------------------------------- /BigBasket.java: -------------------------------------------------------------------------------- 1 | package first21Days; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.Keys; 7 | import org.openqa.selenium.UnexpectedAlertBehaviour; 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 | import org.openqa.selenium.remote.CapabilityType; 13 | import org.openqa.selenium.remote.DesiredCapabilities; 14 | import org.openqa.selenium.support.ui.Select; 15 | 16 | public class BigBasket { 17 | 18 | public static void main(String[] args) throws InterruptedException { 19 | System.setProperty("webdriver.chrome.silentOutput", "true"); 20 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 21 | // disable the notifications 22 | ChromeOptions options = new ChromeOptions(); 23 | options.addArguments("--disable-notifications"); 24 | 25 | DesiredCapabilities cap = new DesiredCapabilities(); 26 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 27 | options.merge(cap); 28 | // Launching Chrome Browser 29 | ChromeDriver driver = new ChromeDriver(options); 30 | // To Load the url 31 | driver.get("https://www.bigbasket.com/"); 32 | // To maximize the browser 33 | driver.manage().window().maximize(); 34 | // implicitly wait 35 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 36 | driver.findElementByXPath("//span[@class='close-btn']").click(); 37 | Thread.sleep(1000); 38 | // mouse over on Shop by Category 39 | WebElement eleCategory = driver.findElementByXPath("//a[text()=' Shop by Category ']"); 40 | Actions builder = new Actions(driver); 41 | builder.moveToElement(eleCategory).perform(); 42 | Thread.sleep(1000); 43 | 44 | // Go to FOODGRAINS, OIL & MASALA --> RICE & RICE PRODUCTS 45 | WebElement elefood = driver.findElementByXPath("(//a[text()='Foodgrains, Oil & Masala'])[2]"); 46 | Actions builder1 = new Actions(driver); 47 | builder1.moveToElement(elefood).perform(); 48 | Thread.sleep(3000); 49 | WebElement elerice = driver.findElementByXPath("(//a[text()='Rice & Rice Products'])[2]"); 50 | Actions builder2 = new Actions(driver); 51 | builder2.moveToElement(elerice).perform(); 52 | Thread.sleep(3000); 53 | 54 | // Click on Boiled & Steam Rice 55 | driver.findElementByXPath("(//a[text()='Boiled & Steam Rice'])[2]").click(); 56 | Thread.sleep(6000); 57 | // Choose the Brand as bb Royal 58 | driver.findElementByXPath("(//span[text()='bb Royal'])[1]").click(); 59 | Thread.sleep(5000); 60 | // Go to Ponni Boiled Rice - Super Premium and select 5kg bag from Dropdown 61 | driver.findElementByXPath( 62 | "(//a[text()='Ponni Boiled Rice - Super Premium']/following::div[@class='btn-group btn-input clearfix ng-scope'])[1]") 63 | .click(); 64 | driver.findElementByXPath( 65 | "(//a[text()='Ponni Boiled Rice - Super Premium']/following::span[contains(text(),'5 kg')])[1]") 66 | .click(); 67 | 68 | // print the price of Rice 69 | String ricePrice = driver 70 | .findElementByXPath( 71 | "(//a[text()='Ponni Boiled Rice - Super Premium']/following::span[@class='discnt-price'])[1]") 72 | .getText(); 73 | System.out.println("The price of the rice is " + ricePrice); 74 | 75 | // Click Add button 76 | driver.findElementByXPath("(//a[text()='Ponni Boiled Rice - Super Premium']/following::button[@qa='add'])[1]") 77 | .click(); 78 | Thread.sleep(2000); 79 | // driver.findElementByXPath("(//a[text()='Continue'])[1]").click(); 80 | // Thread.sleep(4000); 81 | 82 | // Verify the success message displayed 83 | String addMsg = driver.findElementByXPath("//div[@class='toast-title']").getText(); 84 | if (addMsg.equalsIgnoreCase("Successfully added Ponni Boiled Rice - Super Premium 5 kg to the basket")) { 85 | System.out.println("The meassage after adding rice into cart is " + addMsg); 86 | Thread.sleep(3000); 87 | } else { 88 | System.out.println("Wrong message displayed" + addMsg); 89 | } 90 | // Type Dal in Search field and enter 91 | driver.findElementByXPath("//input[@id='input']").sendKeys("DAL", Keys.ENTER); 92 | Thread.sleep(3000); 93 | // Go to Toor/Arhar Dal and select 2kg & set Qty 2 94 | driver.findElementByXPath( 95 | "(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::div[@class='btn-group btn-input clearfix ng-scope'])[1]") 96 | .click(); 97 | driver.findElementByXPath( 98 | "(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::span[contains(text(),'2 kg')])[1]").click(); 99 | WebElement quantity = driver 100 | .findElementByXPath("(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::input)[1]"); 101 | quantity.clear(); 102 | quantity.sendKeys("2"); 103 | 104 | // Print the price of Dal 105 | String dalPrice = driver 106 | .findElementByXPath( 107 | "(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::span[@class='discnt-price'])[1]") 108 | .getText(); 109 | System.out.println("The Price of Dal is " + dalPrice); 110 | // Click Add button 111 | driver.findElementByXPath("(//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::button[@qa='add'])[1]") 112 | .click(); 113 | Thread.sleep(2000); 114 | 115 | String addMsgDal = driver.findElementByXPath("//div[@class='toast-title']").getText(); 116 | if (addMsgDal.equalsIgnoreCase("Successfully added Toor/Arhar Dal/Thuvaram Paruppu 2 kg to the basket")) { 117 | System.out.println("The meassage after adding dal into cart is " + addMsgDal); 118 | } else { 119 | System.out.println("Wrong message displayed" + addMsgDal); 120 | } 121 | driver.findElementByXPath("//button[@class='toast-close-button']").click(); 122 | // Mouse hover on My Basket 123 | WebElement elecart = driver.findElementByXPath("//span[@class='basket-content']"); 124 | Actions builder3 = new Actions(driver); 125 | builder3.moveToElement(elecart).perform(); 126 | Thread.sleep(3000); 127 | 128 | // Validate the Sub Total displayed for the selected items 129 | String subTotal = driver.findElementByXPath("//span[@qa='subTotalMB']").getText(); 130 | // System.out.println(subTotal); 131 | // String total = subTotal.replaceAll("\\D", ""); 132 | double dblSTotal = Double.parseDouble(subTotal); 133 | System.out.println("Subtotal before reducing the Quantity of dhal is " + dblSTotal); 134 | System.out.println(" "); 135 | 136 | String rPrice = driver.findElementByXPath("(//span[@qa='priceMB'])[1]").getText(); 137 | String rQuantity = driver.findElementByXPath("(//div[@qa='pcsMB'])[1]").getText(); 138 | String riceQuantity = rQuantity.substring(0, 1); 139 | // System.out.println(riceQuantity); 140 | double totalRiceQuantity = Double.parseDouble(riceQuantity); 141 | double priceOfRice = Double.parseDouble(rPrice); 142 | double riceTotalPrice = totalRiceQuantity * priceOfRice; 143 | System.out.println("Total Price of Rice is " + riceTotalPrice); 144 | System.out.println(" "); 145 | 146 | String dPrice = driver.findElementByXPath("(//span[@qa='priceMB'])[2]").getText(); 147 | String dQuantity = driver.findElementByXPath("(//div[@qa='pcsMB'])[2]").getText(); 148 | String dalQuantity = dQuantity.substring(0, 1); 149 | // System.out.println(dalQuantity); 150 | double totalDalQuantity = Double.parseDouble(dalQuantity); 151 | double priceOfDal = Double.parseDouble(dPrice); 152 | double dalTotalPrice = totalDalQuantity * priceOfDal; 153 | System.out.println("Total price of dal before reducing the Quantity is " + dalTotalPrice); 154 | System.out.println(" "); 155 | 156 | double overallTotal = riceTotalPrice + dalTotalPrice; 157 | if (dblSTotal == overallTotal) { 158 | System.out.println( 159 | "The SubTotal is validated with the calculated amount for the products before reducing the Quantity"); 160 | } else { 161 | System.out.println("The subtotal is getting mismatched"); 162 | } 163 | System.out.println(" "); 164 | System.out.println(" "); 165 | 166 | // Reduce the Quantity of Dal as 1 167 | driver.findElementByXPath("(//button[@qa='decQtyMB'])[2]").click(); 168 | Thread.sleep(1000); 169 | // Validate the Sub Total for the current items 170 | String dPrice1 = driver.findElementByXPath("(//span[@qa='priceMB'])[2]").getText(); 171 | String dQuantity1 = driver.findElementByXPath("(//div[@qa='pcsMB'])[2]").getText(); 172 | String dalQuantity1 = dQuantity1.substring(0, 1); 173 | // System.out.println(dalQuantity1); 174 | double totalDalQuantity1 = Double.parseDouble(dalQuantity1); 175 | double priceOfDal1 = Double.parseDouble(dPrice1); 176 | double dalTotalPrice1 = totalDalQuantity1 * priceOfDal1; 177 | System.out.println("Total price of dal after reducing the quantity is " + dalTotalPrice1); 178 | System.out.println(" "); 179 | 180 | String subTotal1 = driver.findElementByXPath("//span[@qa='subTotalMB']").getText(); 181 | double dblSTotal1 = Double.parseDouble(subTotal1); 182 | System.out.println("Subtotal after reducing the quantity of dal is " + dblSTotal1); 183 | System.out.println(" "); 184 | 185 | double overallTotal1 = riceTotalPrice + dalTotalPrice1; 186 | 187 | if (dblSTotal1 == overallTotal1) { 188 | System.out.println( 189 | "The SubTotal is validated with the calculated amount for the products after reducing the quantity of dal"); 190 | } else { 191 | System.out.println("The subtotal is getting mismatched"); 192 | } 193 | 194 | // Close the Browser 195 | driver.close(); 196 | } 197 | 198 | } 199 | -------------------------------------------------------------------------------- /CRM.java: -------------------------------------------------------------------------------- 1 | package first21Days; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.UnexpectedAlertBehaviour; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | import org.openqa.selenium.chrome.ChromeOptions; 10 | import org.openqa.selenium.interactions.Action; 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 CRM { 19 | 20 | public static void main(String[] args) throws InterruptedException { 21 | System.setProperty("webdriver.chrome.silentOutput", "true"); 22 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 23 | // disable the notifications 24 | ChromeOptions options = new ChromeOptions(); 25 | options.addArguments("--disable-notifications"); 26 | 27 | DesiredCapabilities cap = new DesiredCapabilities(); 28 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 29 | options.merge(cap); 30 | // Launching Chrome Browser 31 | ChromeDriver driver = new ChromeDriver(options); 32 | // To Load the url 33 | driver.get("https://demo.1crmcloud.com/"); 34 | // To maximize the browser 35 | driver.manage().window().maximize(); 36 | // implicitly wait 37 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 38 | 39 | //2) Give username as admin and password as admin 40 | driver.findElementById("login_user").sendKeys("admin"); 41 | driver.findElementById("login_pass").sendKeys("admin"); 42 | 43 | //3) Choose theme as Claro Theme 44 | WebElement selectTheme = driver.findElementById("login_theme"); 45 | Select theme = new Select(selectTheme); 46 | theme.selectByVisibleText("Claro Theme"); 47 | driver.findElementById("login_button").click(); 48 | Thread.sleep(3000); 49 | 50 | //4) Click on Sales and Marketting 51 | driver.findElementByXPath("//div[text()='Sales & Marketing']").click(); 52 | Thread.sleep(3000); 53 | 54 | //5) Click Create contact 55 | driver.findElementByXPath("//div[text()='Create Contact']").click(); 56 | Thread.sleep(5000); 57 | 58 | //6) Select Title and type First name, Last Name, Email and Phone Numbers 59 | // WebDriverWait wait = new WebDriverWait(driver, 10); 60 | //wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@id='DetailFormsalutation-input']"))); 61 | driver.findElementByXPath("//div[@id='DetailFormsalutation-input']").click(); 62 | Thread.sleep(500); 63 | driver.findElementByXPath("//div[text()='Mrs.']").click(); 64 | driver.findElementById("DetailFormfirst_name-input").sendKeys("Pavithra"); 65 | driver.findElementById("DetailFormlast_name-input").sendKeys("Srinivasan"); 66 | driver.findElementById("DetailFormemail1-input").sendKeys("pavi7@gmail.com"); 67 | driver.findElementById("DetailFormphone_work-input").sendKeys("9710724561"); 68 | 69 | //7) Select Lead Source as "Public Relations" 70 | driver.findElementById("DetailFormlead_source-input").click(); 71 | Thread.sleep(500); 72 | driver.findElementByXPath("//div[text()='Public Relations']").click(); 73 | Thread.sleep(1000); 74 | //8) Select Business Roles as "Sales" 75 | driver.findElementById("DetailFormbusiness_role-input").click(); 76 | Thread.sleep(500); 77 | driver.findElementByXPath("//div[text()='Sales']").click(); 78 | Thread.sleep(1000); 79 | 80 | //9) Fill the Primary Address, City, State, Country and Postal Code and click Save 81 | driver.findElementById("DetailFormprimary_address_street-input").sendKeys("D 205, MGR Road, Nanganallur"); 82 | driver.findElementById("DetailFormprimary_address_city-input").sendKeys("Chennai"); 83 | driver.findElementById("DetailFormprimary_address_state-input").sendKeys("TamilNadu"); 84 | driver.findElementById("DetailFormprimary_address_country-input").sendKeys("India"); 85 | driver.findElementById("DetailFormprimary_address_postalcode-input").sendKeys("600061"); 86 | driver.findElementById("DetailForm_save2").click(); 87 | Thread.sleep(5000); 88 | 89 | //10) Mouse over on Today's Activities and click Meetings 90 | WebElement todayActivities = driver.findElementByXPath("(//div[@class='menu-label'])[1]"); 91 | Actions builder = new Actions(driver); 92 | builder.moveToElement(todayActivities).perform(); 93 | Thread.sleep(1000); 94 | driver.findElementByXPath("//div[text()='Meetings']").click(); 95 | Thread.sleep(5000); 96 | 97 | //11) Click Create 98 | driver.findElementByXPath("(//button[@class='input-button first'])[1]").click(); 99 | Thread.sleep(5000); 100 | 101 | //12) Type Subject as "Project Status" , Status as "Planned" 102 | driver.findElementById("DetailFormname-input").sendKeys("Project Status"); 103 | 104 | 105 | //13) Start Date & Time as tomorrow 3 pm and Duration as 1hr 106 | driver.executeScript("window.scrollBy(0, 250)"); 107 | driver.findElementByXPath("//div[@id='DetailFormdate_start-input']").click(); 108 | Thread.sleep(1000); 109 | //WebDriverWait wait = new WebDriverWait(driver, 10); 110 | //wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//div[@class='grid-cell number-cell text-right day inside current selected quiet responsive']/following::div)[1]"))); 111 | driver.findElementByXPath("(//div[@class='grid-cell number-cell text-right day inside current selected quiet responsive']/following::div)[1]").click(); 112 | driver.findElementByXPath("(//input[@class='input-text'])[4]").clear(); 113 | driver.findElementByXPath("(//input[@class='input-text'])[4]").sendKeys("15:00"); 114 | driver.findElementByXPath("//div[@class='active-icon uii-accept uii-lg uii']").click(); 115 | Thread.sleep(1000); 116 | driver.findElementById("DetailFormduration-time").clear(); 117 | driver.findElementById("DetailFormduration-time").sendKeys("1h 00m",Keys.TAB); 118 | 119 | //14) Click Add paricipants, add your created Contact name and click Save 120 | driver.findElementByXPath("//button[@name='addInvitee']").click(); 121 | Thread.sleep(500); 122 | driver.findElementByXPath("(//input[@class='input-text'])[4]").sendKeys("Pavithra"); 123 | Thread.sleep(500); 124 | driver.findElementByXPath("(//div[@class='option-cell input-label '])[14]").click(); 125 | driver.findElementByXPath("//span[@id='DetailForm_save2-label']").click(); 126 | Thread.sleep(5000); 127 | String proTitle = driver.findElementByXPath("//div[@id='_form_header']").getText(); 128 | 129 | //15) Go to Sales and Marketting-->Contacts 130 | WebElement salesMarketing = driver.findElementByXPath("//div[text()='Sales & Marketing']"); 131 | Actions builder1 = new Actions(driver); 132 | builder1.moveToElement(salesMarketing).perform(); 133 | Thread.sleep(1000); 134 | driver.findElementByXPath("//div[text()='Contacts']").click(); 135 | Thread.sleep(5000); 136 | 137 | //16) search the lead Name and click the name from the result 138 | driver.findElementByXPath("//input[@id='filter_text']").sendKeys("Pavithra"); 139 | Thread.sleep(500); 140 | driver.findElementByXPath("(//div[@class='menu-option single'])[15]").click(); 141 | // Thread.sleep(2000); 142 | //driver.findElementByXPath("//span[@class='detailLink']").click(); 143 | Thread.sleep(5000); 144 | //17) Check weather the Meeting is assigned to the contact under Activities Section. 145 | driver.executeScript("window.scrollBy(0, 750)"); 146 | String projectName = driver.findElementByXPath("//span[@class='detailLink']").getText(); 147 | if(projectName.equalsIgnoreCase(proTitle)) { 148 | System.out.println("The Meeting is scheduled to the created contact under activities section"); 149 | }else { 150 | System.out.println("The Meeting is not scheduled to the created contact under activities section"); 151 | } 152 | 153 | //close the window 154 | driver.close(); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /Carwale.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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.Set; 9 | import java.util.Map.Entry; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import org.openqa.selenium.JavascriptExecutor; 13 | import org.openqa.selenium.Keys; 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.remote.DesiredCapabilities; 18 | import org.openqa.selenium.support.ui.ExpectedConditions; 19 | import org.openqa.selenium.support.ui.Select; 20 | import org.openqa.selenium.support.ui.WebDriverWait; 21 | 22 | public class Carwale { 23 | 24 | public static void main(String[] args) throws InterruptedException { 25 | // 1) Go to https://www.carwale.com/ 26 | System.setProperty("webdriver.chrome.silentOutput", "true"); 27 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 28 | // disable the notifications 29 | 30 | ChromeOptions options = new ChromeOptions(); 31 | options.addArguments("--disable-notifications"); 32 | DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 33 | 34 | options.addArguments("--incognito"); 35 | capabilities.setCapability(ChromeOptions.CAPABILITY, options); 36 | // Launching Chrome Browser 37 | ChromeDriver driver = new ChromeDriver(options); 38 | // To Load the url 39 | driver.get("https://www.carwale.com/"); 40 | // To maximize the browser 41 | driver.manage().window().maximize(); 42 | // implicitly wait 43 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 44 | WebDriverWait wait = new WebDriverWait(driver, 30); 45 | JavascriptExecutor js = (JavascriptExecutor) driver; 46 | // 2) Click on Used 47 | driver.findElementByXPath("//li[@data-tabs='usedCars']").click(); 48 | 49 | // 3) Select the City as Chennai 50 | driver.findElementByXPath("//input[@id='usedCarsList']").sendKeys("Chennai"); 51 | driver.findElementByXPath("//a[@cityname='chennai,tamilnadu']").click(); 52 | 53 | // 4) Select budget min (8L) and max(12L) and Click Search 54 | driver.findElementByXPath("//li[text()='8 Lakh']").click(); 55 | driver.findElementByXPath("(//li[text()='12 Lakh'])[2]").click(); 56 | driver.findElementByXPath("(//span[@class='welcome-box__search-icon'])[2]").click(); 57 | Thread.sleep(2000); 58 | 59 | // 5) Select Cars with Photos under Only Show Cars With 60 | driver.findElementByXPath("//span[text()='Cars with Photos']").click(); 61 | Thread.sleep(3000); 62 | 63 | // 6) Select Manufacturer as "Hyundai" --> Creta 64 | 65 | // wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//li[@data-manufacture-en='Hyundai']//span)[1]"))); 66 | WebElement slcHyundai = driver.findElementByXPath("(//li[@data-manufacture-en='Hyundai']//span)[1]"); 67 | js.executeScript("arguments[0].click()", slcHyundai); 68 | // wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//span[text()='Creta']"))); 69 | WebElement slcCreta = driver.findElementByXPath("//span[text()='Creta']"); 70 | js.executeScript("arguments[0].click()", slcCreta); 71 | Thread.sleep(3000); 72 | 73 | // 7) Select Fuel Type as Petrol 74 | WebElement eleFuelType = driver.findElementByXPath("//h3[contains(text(),'Fuel Type')]"); 75 | js.executeScript("arguments[0].click()", eleFuelType); 76 | WebElement elePetrol = driver.findElementByXPath("//li[contains(@name,'Petrol')]"); 77 | js.executeScript("arguments[0].click()", elePetrol); 78 | Thread.sleep(3000); 79 | 80 | // 8) Select Best Match as "KM: Low to High" 81 | WebElement eleBestMatch = driver.findElementById("sort"); 82 | Select eleprice = new Select(eleBestMatch); 83 | eleprice.selectByVisibleText("KM: Low to High"); 84 | Thread.sleep(3000); 85 | 86 | // 9) Validate the Cars are listed with KMs Low to High 87 | String kmsValues = ""; 88 | List intKms = new ArrayList(); 89 | List lowKms = driver.findElementsByXPath("//span[@class='slkms vehicle-data__item']"); 90 | int sizeKms = lowKms.size(); 91 | for (int i = 0; i < sizeKms; i++) { 92 | kmsValues = lowKms.get(i).getText(); 93 | String reKms = kmsValues.replaceAll("[^0-9]", ""); 94 | int onlyKmsNos = Integer.parseInt(reKms); 95 | intKms.add(onlyKmsNos); 96 | 97 | } 98 | // System.out.println(intKms); 99 | List sortKms = new ArrayList(intKms); 100 | Collections.sort(sortKms); 101 | 102 | if (intKms.equals(sortKms)) { 103 | System.out.println("The Kilometers are sorted from Low to High"); 104 | } else { 105 | System.out.println("The Kilometers are not sorted from Low to High"); 106 | } 107 | 108 | // 10) Add the least KM ran car to Wishlist 109 | for (int j = 0; j < sizeKms; j++) { 110 | if (intKms.get(j).equals(sortKms.get(0))) { 111 | WebElement addToCart = driver 112 | .findElementByXPath("(//span[@class='shortlist-icon--inactive shortlist'])[" + (j + 1) + "]"); 113 | js.executeScript("arguments[0].click()", addToCart); 114 | Thread.sleep(2000); 115 | break; 116 | } 117 | } 118 | // 11) Go to Wishlist and Click on More Details 119 | WebElement wishList = driver.findElementByXPath("//li[@data-action='ShortList&CompareWindow_Click']"); 120 | js.executeScript("arguments[0].click()", wishList); 121 | 122 | WebElement moreDetails = driver.findElementByXPath("//a[contains(text(),'More details')]"); 123 | js.executeScript("arguments[0].click()", moreDetails); 124 | 125 | Thread.sleep(3000); 126 | 127 | // 12) Print all the details under Overview in the Same way as displayed in 128 | // application 129 | Set allWindows = driver.getWindowHandles(); 130 | List allList = new ArrayList(allWindows); 131 | driver.switchTo().window(allList.get(1)); 132 | Map details = new LinkedHashMap(); 133 | List overview = driver 134 | .findElementsByXPath("//div[@id='overview']//div[@class='equal-width text-light-grey']"); 135 | List features = driver 136 | .findElementsByXPath("//div[@id='overview']//div[@class='equal-width dark-text']"); 137 | int detailsSize = overview.size(); 138 | for (int k = 0; k < detailsSize; k++) { 139 | String mapOverview = overview.get(k).getText(); 140 | String mapFeatures = features.get(k).getText(); 141 | details.put(mapOverview, mapFeatures); 142 | } 143 | 144 | for (Entry each : details.entrySet()) { 145 | System.out.println(each.getKey() + " ---------- " + each.getValue()); 146 | 147 | } 148 | //13) Close the browser. 149 | driver.quit(); 150 | 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /Honda.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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.chrome.ChromeOptions; 14 | import org.openqa.selenium.interactions.Actions; 15 | import org.openqa.selenium.support.ui.Select; 16 | 17 | public class Honda { 18 | 19 | public static void main(String[] args) throws InterruptedException { 20 | System.setProperty("webdriver.chrome.silentOutput", "true"); 21 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 22 | // disable the notifications 23 | ChromeOptions options = new ChromeOptions(); 24 | options.addArguments("--disable-notifications"); 25 | // Launching Chrome Browser 26 | ChromeDriver driver = new ChromeDriver(options); 27 | // To Load the url 28 | driver.get("https://www.honda2wheelersindia.com/"); 29 | // To maximize the browser 30 | driver.manage().window().maximize(); 31 | // implicitly wait 32 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 33 | driver.findElementByXPath("//button[@class='close']").click(); 34 | 35 | // Click on scooters and click dio 36 | driver.findElementByXPath("(//a[text()='Scooter'])[1]").click(); 37 | // driver.findElementByXPath("(//div[@class='owl-item']/following::img)[3]").click(); 38 | driver.findElementByXPath("//img[@src='/assets/images/thumb/dioBS6-icon.png']").click(); 39 | 40 | // Click on Specifications and mouseover on ENGINE 41 | driver.findElementByXPath("//a[text()='Specifications']").click(); 42 | Thread.sleep(2000); 43 | WebElement eleengine1 = driver.findElementByXPath("//a[text()='ENGINE']"); 44 | Actions builder = new Actions(driver); 45 | builder.moveToElement(eleengine1).perform(); 46 | Thread.sleep(1000); 47 | // Get Displacement value 48 | String dioDisplacement = driver.findElementByXPath("//span[text()='Displacement']/following-sibling::span") 49 | .getText(); 50 | System.out.println("The displacement value of DIO is " + dioDisplacement); 51 | String rDioDisplacement = dioDisplacement.replace("c", " "); 52 | // System.out.println(rdioDisplacement); 53 | float flDioDisplacement = Float.parseFloat(rDioDisplacement); 54 | // System.out.println(fldioDisplacement); 55 | 56 | // Go to Scooters and click Activa 125 57 | driver.findElementByXPath("(//a[text()='Scooter'])[1]").click(); 58 | Thread.sleep(2000); 59 | // driver.findElementByXPath("(//div[@class='owl-item']/following::img)[5]").click(); 60 | driver.findElementByXPath("//img[@src='/assets/images/thumb/activa-125new-icon.png']").click(); 61 | 62 | // Click on Specifications and mouseover on ENGINE 63 | driver.findElementByXPath("//a[text()='Specifications']").click(); 64 | Thread.sleep(3000); 65 | WebElement eleengine2 = driver.findElementByXPath("//a[text()='ENGINE']"); 66 | Actions builder2 = new Actions(driver); 67 | builder2.moveToElement(eleengine2).perform(); 68 | Thread.sleep(2000); 69 | // Get Displacement value 70 | String activaDisplacement = driver.findElementByXPath("//span[text()='Displacement']/following-sibling::span") 71 | .getText(); 72 | System.out.println("The displacement value of DIO is " + activaDisplacement); 73 | String rActivaDisplacement = activaDisplacement.replace("c", " "); 74 | float flActivaDisplacement = Float.parseFloat(rActivaDisplacement); 75 | 76 | // Compare Displacement of Dio and Activa 125 and print the Scooter name having 77 | // better Displacement. 78 | if (flActivaDisplacement > flDioDisplacement) { 79 | System.out.println("Activa 125 has better displacement"); 80 | } else { 81 | System.out.println("Dio has better displacement"); 82 | } 83 | 84 | // Click FAQ from Menu 85 | driver.findElementByXPath("(//a[text()='FAQ'])[1]").click(); 86 | Thread.sleep(2000); 87 | 88 | // Click Activa 125 BS-VI under Browse By Product 89 | WebElement activa125 = driver.findElementByXPath("//a[text()='Activa 125 BS-VI']"); 90 | activa125.click(); 91 | Thread.sleep(2000); 92 | // Click Vehicle Price 93 | driver.findElementByXPath("//a[text()=' Vehicle Price']").click(); 94 | 95 | // Make sure Activa 125 BS-VI selected and click submit 96 | WebElement modelDD = driver.findElementById("ModelID6"); 97 | Select model = new Select(modelDD); 98 | String selectedModel = model.getFirstSelectedOption().getText(); 99 | // System.out.println(selectedModel); 100 | if (selectedModel.equalsIgnoreCase("Activa 125 BS-VI")) { 101 | driver.findElementByXPath("//button[@id='submit6']").click(); 102 | } else { 103 | System.out.println("The selected vehicle is not Activa 125 BS-VI"); 104 | } 105 | // click the price link 106 | driver.findElementByXPath("//a[text()='Click here to know the price of Activa 125 BS-VI.']").click(); 107 | Thread.sleep(3000); 108 | 109 | // Go to the new Window and select the state as Tamil Nadu and city as Chennai 110 | Set nextWindow = driver.getWindowHandles(); 111 | List allList = new ArrayList(nextWindow); 112 | driver.switchTo().window(allList.get(1)); 113 | // state selected as Tamil Nadu 114 | WebElement stateId = driver.findElementById("StateID"); 115 | Select selectStateId = new Select(stateId); 116 | selectStateId.selectByVisibleText("Tamil Nadu"); 117 | // city selected as Chennai 118 | WebElement cityId = driver.findElementById("CityID"); 119 | Select selectCityId = new Select(cityId); 120 | selectCityId.selectByVisibleText("Chennai"); 121 | 122 | // Click Search 123 | driver.findElementByXPath("//button[text()='Search']").click(); 124 | 125 | // Print all the 3 models and their prices 126 | 127 | Map priceOfScooters = new LinkedHashMap(); 128 | 129 | String scooterModel = ""; 130 | String price = ""; 131 | 132 | for (int i = 1; i <= 3; i++) { 133 | scooterModel = driver 134 | .findElementByXPath("//table[@id='gvshow']//tr[" + i + "]//td[contains(text(),'ACTIVA')]") 135 | .getText(); 136 | price = driver 137 | .findElementByXPath( 138 | "//table[@id='gvshow']//tr[" + i + "]//td[contains(text(),'ACTIVA')]/following-sibling::td") 139 | .getText(); 140 | 141 | priceOfScooters.put(scooterModel, price); 142 | 143 | } 144 | 145 | for (Entry each : priceOfScooters.entrySet()) { 146 | System.out.println(each.getKey() + " price is " + each.getValue()); 147 | 148 | } 149 | 150 | // Close the Browser 151 | driver.quit(); 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /HpProgram.java: -------------------------------------------------------------------------------- 1 | package first21Days; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.openqa.selenium.chrome.ChromeOptions; 8 | import org.openqa.selenium.interactions.Actions; 9 | import org.openqa.selenium.support.ui.ExpectedCondition; 10 | import org.openqa.selenium.support.ui.Select; 11 | import org.openqa.selenium.support.ui.WebDriverWait; 12 | 13 | public class HpProgram { 14 | 15 | public static void main(String[] args) throws InterruptedException { 16 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 17 | // Launching Chrome Browser 18 | ChromeDriver driver = new ChromeDriver(); 19 | // To Load the url https://store.hp.com/in-en/ 20 | driver.get("https://store.hp.com/in-en/"); 21 | // To maximize the browser 22 | driver.manage().window().maximize(); 23 | // implicitly wait 24 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 25 | 26 | // Mouse over on Laptops menu and click on Pavilion 27 | WebElement eleLaptop = driver.findElementByXPath("(//span[text()='Laptops'])[1]"); 28 | Actions builder = new Actions(driver); 29 | builder.moveToElement(eleLaptop).perform(); 30 | driver.findElementByXPath("(//span[text()='Pavilion'])[1]").click(); 31 | Thread.sleep(2000); 32 | 33 | driver.findElementByXPath("(//span[text()='Processor'])[2]").click(); 34 | driver.findElementByXPath("(//input[@class='product-filter-checkbox'])[2]").click(); 35 | Thread.sleep(3000); 36 | 37 | // Hard Drive Capacity -->More than 1TB 38 | driver.findElementByXPath("//span[text()='More than 1 TB']").click(); 39 | Thread.sleep(4000); 40 | // Select Sort By: Price: Low to High 41 | WebElement sort = driver.findElementById("sorter"); 42 | Select sortAsc = new Select(sort); 43 | sortAsc.selectByVisibleText("Price : Low to High"); 44 | Thread.sleep(4000); 45 | // Print the First resulting Product Name and Price 46 | String laptopName = driver.findElementByXPath("(//a[@class='product-item-link'])[1]").getText(); 47 | System.out.println("The Product name is " + laptopName); 48 | String productPrice = driver.findElementByXPath("(//span[@class='price'])[2]").getText(); 49 | System.out.println("The Product price is " + productPrice); 50 | // Click on Add to Cart 51 | driver.findElementByXPath("(//button[@title='Add To Cart'])[1]").click(); 52 | Thread.sleep(3000); 53 | // Click on Shopping Cart icon --> Click on View and Edit Cart 54 | driver.findElementByXPath("//a[@title='Shopping Cart']").click(); 55 | driver.findElementByXPath("//a[@class='action primary viewcart']").click(); 56 | Thread.sleep(4000); 57 | // Check the Shipping Option --> Check availability at Pincode 58 | driver.findElementByXPath("//input[@name='pincode']").sendKeys("600061"); 59 | driver.findElementByXPath("//button[text()='check']").click(); 60 | Thread.sleep(2000); 61 | driver.findElementByXPath("//div[@class='inside_closeButton fonticon icon-hclose']").click(); 62 | 63 | // Verify the order Total against the product price 64 | String orderTotal = driver.findElementByXPath("(//span[@class='price'])[7]").getText(); 65 | System.out.println("The Order total is " + orderTotal); 66 | Thread.sleep(5000); 67 | boolean price; 68 | if (orderTotal.equalsIgnoreCase(productPrice)) { 69 | price = true; 70 | } else { 71 | price = false; 72 | } 73 | // Proceed to Checkout if Order Total and Product Price matches 74 | if (price == true) { 75 | driver.findElementByXPath("(//span[text()='Proceed to Checkout'])[1]").click(); 76 | Thread.sleep(3000); 77 | } else { 78 | System.out.println("The price didnt match"); 79 | } 80 | // Click on Place Order 81 | driver.findElementByXPath("(//span[text()='Place Order'])[4]").click(); 82 | 83 | // Capture the Error message and Print 84 | String errMsg = driver.findElementByXPath("//div[@class='message notice']").getText(); 85 | System.out.println("The Error message is " + errMsg); 86 | 87 | // Close Browser 88 | driver.close(); 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /JustDial2.java: -------------------------------------------------------------------------------- 1 | package first21Days; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.LinkedHashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Map.Entry; 12 | import java.util.NoSuchElementException; 13 | import java.util.concurrent.TimeUnit; 14 | 15 | import org.apache.poi.xssf.usermodel.XSSFRow; 16 | import org.apache.poi.xssf.usermodel.XSSFSheet; 17 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 18 | import org.openqa.selenium.Keys; 19 | import org.openqa.selenium.UnexpectedAlertBehaviour; 20 | import org.openqa.selenium.WebElement; 21 | import org.openqa.selenium.chrome.ChromeDriver; 22 | import org.openqa.selenium.chrome.ChromeOptions; 23 | import org.openqa.selenium.remote.CapabilityType; 24 | import org.openqa.selenium.remote.DesiredCapabilities; 25 | import org.openqa.selenium.support.ui.ExpectedConditions; 26 | import org.openqa.selenium.support.ui.WebDriverWait; 27 | 28 | public class JustDial2 { 29 | 30 | public static void main(String[] args) throws InterruptedException, IOException { 31 | 32 | //1) https://www.justdial.com/ 33 | System.setProperty("webdriver.chrome.silentOutput", "true"); 34 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 35 | // disable the notifications 36 | 37 | ChromeOptions options = new ChromeOptions(); 38 | options.addArguments("--disable-notifications"); 39 | 40 | // Launching Chrome Browser 41 | ChromeDriver driver = new ChromeDriver(options); 42 | // To Load the url 43 | driver.get("https://www.justdial.com/"); 44 | // To maximize the browser 45 | driver.manage().window().maximize(); 46 | // implicitly wait 47 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 48 | String actPh = ""; 49 | 50 | //2) Set the Location as Chennai 51 | // driver.findElementByXPath("//input[@id='city']").clear(); 52 | // driver.findElementByXPath("//input[@id='city']").sendKeys("Chennai"); 53 | // driver.findElementByXPath("//b[text()='Chennai']").click(); 54 | //3) Click Auto Care in the left menu 55 | driver.findElementByXPath("//span[text()='Auto care']").click(); 56 | Thread.sleep(1000); 57 | //4) Click Car Repair 58 | driver.findElementByXPath("//span[text()='Car Repair']").click(); 59 | Thread.sleep(1000); 60 | //5) Click Car Brand as Hyundai 61 | driver.findElementByXPath("(//span[text()='Hyundai'])[1]").click(); 62 | Thread.sleep(1000); 63 | //6) Click Make as Hyundai Xcent 64 | driver.findElementByXPath("(//span[text()='Hyundai Xcent'])[1]").click(); 65 | Thread.sleep(2000); 66 | 67 | try { 68 | WebDriverWait wait = new WebDriverWait(driver, 30); 69 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByCssSelector("section#best_deal_div>section>span"))); 70 | driver.findElementByCssSelector("section#best_deal_div>section>span").click(); 71 | }catch(Exception e) { 72 | System.out.println("alert not found"); 73 | } 74 | finally { 75 | Map hm = new LinkedHashMap(); 76 | hm.put("+", "dc"); 77 | hm.put("(", "fe"); 78 | hm.put(")", "hg"); 79 | hm.put("-", "ba"); 80 | hm.put("0", "acb"); 81 | hm.put("1", "yz"); 82 | hm.put("2", "wx"); 83 | hm.put("3", "vu"); 84 | hm.put("4", "ts"); 85 | hm.put("5", "rq"); 86 | hm.put("6", "po"); 87 | hm.put("7", "nm"); 88 | hm.put("8", "lk"); 89 | hm.put("9", "ji"); 90 | List sortedCompanyName = new ArrayList(); 91 | List sortedPhoneNo = new ArrayList(); 92 | List eleRating = driver.findElementsByXPath("//span[@class='green-box']"); 93 | for (int i = 0; i < eleRating.size(); i++) { 94 | String ratingChar = eleRating.get(i).getText(); 95 | float rating = Float.parseFloat(ratingChar); 96 | 97 | if (rating >= 4.5) { 98 | WebElement eleVote = driver.findElementByXPath("(//span[@class='green-box'])["+(i+1)+"]/following-sibling::span[contains(text(),'Votes')]"); 99 | String votesChars = eleVote.getText(); 100 | //System.out.println(votesChars); 101 | String voteallchars = votesChars.trim(); 102 | String votesString = voteallchars.replaceAll("[^0-9]", ""); 103 | int vote = Integer.parseInt(votesString); 104 | //System.out.println(vote); 105 | if (vote > 50) { 106 | String companyName = driver.findElementByXPath("((//span[@class='green-box'])["+(i+1)+"]/preceding::span[@class='lng_cont_name'])["+(i+1)+"]").getText(); 107 | // System.out.println(companyName); 108 | sortedCompanyName.add(companyName); 109 | // System.out.println("To test"); 110 | if(i > 0) { 111 | System.out.println("Entered if loop i > 0"); 112 | List PhoneNum = driver.findElementsByXPath("((//span[@class='green-box'])["+(i+1)+"]/preceding::p[@class='newrtings '])["+i+"]/following-sibling::p/span/span[contains(@class,'mobilesv icon')]"); 113 | int phSize = PhoneNum.size(); 114 | // System.out.println("size is "+phSize); 115 | // System.out.println("Test after list"); 116 | 117 | for(int ph = 0; ph "+name); 121 | String convertedPh = name.substring(14); 122 | // System.out.println("The converted Ph is "+convertedPh); 123 | for (Entry eachEntry: hm.entrySet()) { 124 | if(eachEntry.getValue().equalsIgnoreCase(convertedPh)) { 125 | // System.out.println("key is "+eachEntry.getKey()); 126 | actPh = actPh+(eachEntry.getKey()); 127 | } 128 | } 129 | 130 | } 131 | System.out.println("The value of decoded Ph Number is "+actPh); 132 | sortedPhoneNo.add(actPh); 133 | actPh = ""; 134 | } 135 | else if(i==0){ 136 | // System.out.println("Entered if loop i = 0"); 137 | 138 | List phoneNumI = driver.findElementsByXPath("(//span[@class='green-box'])["+(i+1)+"]/parent::a/parent::p/following-sibling::p/span/span[contains(@class,'mobilesv icon')]"); 139 | int phSizeI = phoneNumI.size(); 140 | // System.out.println("size is "+phSizeI); 141 | // System.out.println("Test after list"); 142 | 143 | for(int ph = 0; ph "+name); 147 | String convertedPh = name.substring(14); 148 | // System.out.println("The converted Ph is "+convertedPh); 149 | for (Entry eachEntry: hm.entrySet()) { 150 | if(eachEntry.getValue().equalsIgnoreCase(convertedPh)) { 151 | // System.out.println("key is "+eachEntry.getKey()); 152 | 153 | actPh = actPh+(eachEntry.getKey()); 154 | } 155 | } 156 | 157 | } 158 | System.out.println("The value of decoded Ph Number is "+actPh); 159 | sortedPhoneNo.add(actPh); 160 | actPh = ""; 161 | } 162 | 163 | 164 | } 165 | } 166 | } 167 | File file = new File("C:\\TestLeaf\\Learning90Days\\output.xlsx"); 168 | XSSFWorkbook wb = new XSSFWorkbook(); 169 | XSSFSheet sh = wb.createSheet("first Sheet"); 170 | for(int j=0 ; j=4.5 and Votes >=50 212 | 213 | 214 | //11) Save all the Service Center name and Phone number matching the above condition in excel 215 | 216 | //12) Close the browser 217 | // driver.close(); 218 | 219 | 220 | -------------------------------------------------------------------------------- /MakeMyTrip.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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.support.ui.Select; 12 | 13 | public class MakeMyTrip { 14 | 15 | public static void main(String[] args) throws InterruptedException { 16 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 17 | // disable the notifications 18 | ChromeOptions options = new ChromeOptions(); 19 | options.addArguments("--disable-notifications"); 20 | // Launching Chrome Browser 21 | ChromeDriver driver = new ChromeDriver(options); 22 | // To Load the url https://www.makemytrip.com/ 23 | driver.get("https://www.makemytrip.com/"); 24 | // To maximize the browser 25 | driver.manage().window().maximize(); 26 | // implicitly wait 27 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 28 | 29 | // Click Hotels 30 | driver.findElementByXPath("//span[@class='chNavIcon appendBottom2 chSprite chHotels']").click(); 31 | 32 | // Enter city as Goa, and choose Goa, India 33 | driver.findElementByXPath("//span[@class='lbl_input latoBold appendBottom5']").click(); 34 | Thread.sleep(3000); 35 | driver.findElementByXPath("//input[@placeholder='Enter city/ Hotel/ Area/ Building']").sendKeys("Goa"); 36 | driver.findElementByXPath("//p[text()='Goa, India']").click(); 37 | 38 | // Enter Check in date as Next month 15th (May 15) and Check out as start date+5 39 | driver.findElementByXPath("(//div[text()='15'])[2]").click(); 40 | driver.findElementByXPath("(//div[text()='19'])[2]").click(); 41 | 42 | // Click on ROOMS & GUESTS and click 2 Adults and one Children(age 12). Click 43 | // Apply Button. 44 | driver.findElementByXPath("//input[@class='hsw_inputField guests font20']").click(); 45 | driver.findElementByXPath("//li[@data-cy='adults-2']").click(); 46 | driver.findElementByXPath("//li[@data-cy='children-1']").click(); 47 | 48 | WebElement childAge = driver.findElementByClassName("ageSelectBox"); 49 | 50 | Select age = new Select(childAge); 51 | age.selectByVisibleText("11"); 52 | driver.findElementByXPath("//button[@class='primaryBtn btnApply']").click(); 53 | 54 | // Click Search button 55 | driver.findElementByXPath("//button[@class='primaryBtn font24 latoBold widgetSearchBtn']").click(); 56 | 57 | // click on the black screen 58 | driver.findElementByXPath("//body[@class='bodyFixed overlayWholeBlack']").click(); 59 | 60 | // Select locality as Baga 61 | driver.findElementByXPath("//label[text()='Baga']").click(); 62 | 63 | // Select 5 start in Star Category under Select Filters 64 | driver.findElementByXPath("//label[text()='5 Star']").click(); 65 | 66 | // Click on the first resulting hotel and go to the new window 67 | driver.findElementByXPath("(//div[@class='imgCont'])[1]").click(); 68 | Set allWindows = driver.getWindowHandles(); 69 | List allhandles = new ArrayList(allWindows); 70 | driver.switchTo().window(allhandles.get(1)); 71 | 72 | // Print the Hotel Name 73 | String hotelName = driver.findElementByXPath("//h1[@id='detpg_hotel_name']").getText(); 74 | System.out.println("The Hotel name is " + hotelName); 75 | 76 | // Click MORE OPTIONS link and Select 3Months plan and close 77 | driver.findElementByXPath("//span[text()='MORE OPTIONS']").click(); 78 | driver.findElementByXPath("(//span[text()='SELECT'])[1]").click(); 79 | driver.findElementByXPath("//span[@class='close']").click(); 80 | 81 | // Click on BOOK THIS NOW 82 | driver.findElementByXPath("//a[text()='BOOK THIS NOW']").click(); 83 | 84 | // Print the Total Payable amount 85 | String totalAmt = driver.findElementByXPath("//span[@id='revpg_total_payable_amt']").getText(); 86 | System.out.println("The Total payable amount is " + totalAmt); 87 | 88 | // Close the browser 89 | driver.quit(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /Myntra.java: -------------------------------------------------------------------------------- 1 | package first21Days; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.chrome.ChromeDriver; 8 | import org.openqa.selenium.chrome.ChromeOptions; 9 | import org.openqa.selenium.interactions.Actions; 10 | 11 | public class Myntra { 12 | 13 | public static void main(String[] args) throws InterruptedException { 14 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 15 | //disable the notifications 16 | ChromeOptions options= new ChromeOptions(); 17 | options.addArguments("--disable-notifications"); 18 | //Launching Chrome Browser 19 | ChromeDriver driver = new ChromeDriver(options); 20 | //To Load the url 21 | driver.get(" https://www.myntra.com/"); 22 | //To maximize the browser 23 | driver.manage().window().maximize(); 24 | //implicitly wait 25 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 26 | 27 | //Mouse over on WOMEN (Actions -> moveToElement 28 | WebElement eleWomen = driver.findElementByXPath("(//a[text()='Women'])[1]"); 29 | Actions builder = new Actions(driver); 30 | builder.moveToElement(eleWomen).perform(); 31 | 32 | //Click Jackets & Coats 33 | driver.findElementByLinkText("Jackets & Coats").click(); 34 | Thread.sleep(3000); 35 | 36 | //Find the total count of item (top) 37 | String count = driver.findElementByXPath("//span[@class='title-count']").getText(); 38 | String totalCount = count.replaceAll("\\D",""); 39 | int tCNum = Integer.parseInt(totalCount); 40 | System.out.println("The total count of items are "+ tCNum ); 41 | 42 | //Validate the sum of categories count matches 43 | String cat1 = driver.findElementByXPath("(//span[@class='categories-num'])[1]").getText(); 44 | String catJacket = cat1.replaceAll("\\D",""); 45 | int catJacketcount = Integer.parseInt(catJacket); 46 | //System.out.println(catJacketcount); 47 | 48 | String cat2 = driver.findElementByXPath("(//span[@class='categories-num'])[2]").getText(); 49 | String catCoat = cat2.replaceAll("\\D",""); 50 | int catCoatcount = Integer.parseInt(catCoat); 51 | //System.out.println(catCoatcount); 52 | 53 | int totalCatCount = catJacketcount +catCoatcount; 54 | //System.out.println(totalCatCount); 55 | if(tCNum == totalCatCount ) { 56 | System.out.println("The sum of categories " + totalCatCount +" equals the total count of items" ); 57 | } 58 | 59 | //Check Coats 60 | driver.findElementByXPath("//label[text()='Coats']").click(); 61 | Thread.sleep(2000); 62 | 63 | // Click + More option under BRAND 64 | driver.findElementByXPath("//div[@class='brand-more']").click(); 65 | Thread.sleep(3000); 66 | //Type MANGO and click checkbox 67 | driver.findElementByXPath("//input[@class='FilterDirectory-searchInput']").sendKeys("MANGO"); 68 | Thread.sleep(3000); 69 | driver.findElementByXPath("//label[@class=' common-customCheckbox']//div[1]").click(); 70 | //Close the pop-up x 71 | driver.findElementByXPath("//span[@class='myntraweb-sprite FilterDirectory-close sprites-remove']").click(); 72 | Thread.sleep(2000); 73 | 74 | //Confirm all the Coats are of brand MANGO 75 | List brand = driver.findElementsByXPath("//h3[@class='product-brand']"); 76 | int brandCount =0; 77 | for (WebElement brandname : brand) { 78 | String bName = brandname.getText(); 79 | if(bName.equalsIgnoreCase("MANGO")) { 80 | brandCount=brandCount+1; 81 | } 82 | 83 | } 84 | if(brandCount == brand.size()) 85 | { 86 | System.out.println("All the items are brand MANGO"); 87 | } 88 | 89 | //Sort by Better Discount 90 | WebElement sortBy = driver.findElementByXPath("//div[@class='sort-sortBy']"); 91 | Actions builder1 = new Actions(driver); 92 | builder1.moveToElement(sortBy).perform(); 93 | 94 | driver.findElementByXPath("//label[text()='Better Discount']").click(); 95 | Thread.sleep(2000); 96 | 97 | //Find the price of first displayed item 98 | List priceofall = driver.findElementsByXPath("//span[@class='product-discountedPrice']"); 99 | String priceOfFirst = priceofall.get(0).getText(); 100 | String itemPrice = priceOfFirst.replaceAll("\\D",""); 101 | int price = Integer.parseInt(itemPrice); 102 | System.out.println("The Price of first item is "+price); 103 | 104 | //Mouse over on size of the first item 105 | WebElement sizeOfFirst = driver.findElementByXPath("(//span[@class='product-discountedPrice'])[1]"); 106 | Actions builder2 = new Actions(driver); 107 | builder2.moveToElement(sizeOfFirst).perform(); 108 | 109 | //Click on WishList Now 110 | driver.findElementByXPath("(//span[@class='product-actionsButton product-wishlist product-prelaunchBtn'])[1]").click(); 111 | 112 | //Close Browser 113 | driver.close(); 114 | } 115 | 116 | 117 | } 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /Nykka.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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 Nykka { 14 | 15 | public static void main(String[] args) throws InterruptedException { 16 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 17 | // disable the notifications 18 | ChromeOptions options = new ChromeOptions(); 19 | options.addArguments("--disable-notifications"); 20 | // Launching Chrome Browser 21 | ChromeDriver driver = new ChromeDriver(options); 22 | // To Load the url https://www.nykaa.com/ 23 | driver.get("https://www.nykaa.com/"); 24 | // To maximize the browser 25 | driver.manage().window().maximize(); 26 | // implicitly wait 27 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 28 | 29 | // Mouseover on Brands and Mouseover on Popular 30 | WebElement eleBrand = driver.findElementByXPath("//a[text()='brands']"); 31 | Actions builder = new Actions(driver); 32 | builder.moveToElement(eleBrand).perform(); 33 | 34 | WebElement elePopular = driver.findElementByXPath("//a[text()='Popular']"); 35 | Actions builder1 = new Actions(driver); 36 | builder1.moveToElement(elePopular).perform(); 37 | 38 | // Click L'Oreal Paris 39 | driver.findElementByXPath("(//li[@class='brand-logo menu-links']//img)[5]").click(); 40 | Thread.sleep(3000); 41 | // Go to the newly opened window and check the title contains L'Oreal Paris 42 | Set allWindows = driver.getWindowHandles(); 43 | List allhandles = new ArrayList(allWindows); 44 | driver.switchTo().window(allhandles.get(1)); 45 | String titleofcurrrentpage = driver.getTitle(); 46 | System.out.println("The Title of the page is " + titleofcurrrentpage); 47 | if (titleofcurrrentpage.contains("L'Oreal Paris")) { 48 | System.out.println("The Title of the page contains L'Oreal paris"); 49 | } else { 50 | System.out.println("The Title of the page doesn't contain L'Oreal paris"); 51 | } 52 | 53 | // Click sort By and select customer top rated 54 | driver.findElementByXPath("//i[@class='fa fa-angle-down']").click(); 55 | driver.findElementByXPath("//input[@id='3']/following-sibling::div[1]").click(); 56 | Thread.sleep(1000); 57 | 58 | // Click Category and click Shampoo 59 | driver.findElementByXPath("(//div[@class='pull-right filter-options-toggle'])[1]").click(); 60 | driver.findElementByXPath("(//label[@for='chk_Shampoo_undefined'])[1]").click(); 61 | 62 | // check whether the Filter is applied with Shampoo 63 | String filterOption = driver.findElementByXPath("//ul[@class='pull-left applied-filter-lists']").getText(); 64 | // System.out.println(filterOption); 65 | if (filterOption.contains("Shampoo")) { 66 | System.out.println("The filter is applied with Shampoo"); 67 | } else { 68 | System.out.println("The filter is not applied with Shampoo"); 69 | } 70 | 71 | //Click on L'Oreal Paris Colour Protect Shampoo 72 | driver.findElementByXPath("//span[text()=\"L'Oreal Paris Colour Protect Shampoo\"]").click(); 73 | 74 | //GO to the new window and select size as 175ml 75 | Set allWindows1 = driver.getWindowHandles(); 76 | List allhandles1 = new ArrayList(allWindows1); 77 | driver.switchTo().window(allhandles1.get(2)); 78 | 79 | driver.findElementByXPath("//span[text()='175ml']").click(); 80 | 81 | //Print the MRP of the product 82 | String mrp = driver.findElementByXPath("(//span[@class='post-card__content-price-offer'])[1]").getText(); 83 | System.out.println(" The MRP of the shampoo is " + mrp); 84 | 85 | // Click on ADD to BAG 86 | driver.findElementByXPath("(//button[@class='combo-add-to-btn prdt-des-btn js--toggle-sbag nk-btn nk-btn-rnd atc-simple m-content__product-list__cart-btn '])[1]").click(); 87 | Thread.sleep(2000); 88 | //Go to Shopping Bag 89 | driver.findElementByXPath("//div[@class='AddBagIcon']").click(); 90 | 91 | //Print the Grand Total amount 92 | String grandTotal = driver.findElementByXPath("//div[@class='value medium-strong']").getText(); 93 | System.out.println("The grand total is " + grandTotal); 94 | 95 | //Click Proceed 96 | driver.findElementByXPath("//button[@class='btn full fill no-radius proceed ']").click(); 97 | Thread.sleep(3000); 98 | 99 | //Click on Continue as Guest 100 | driver.findElementByXPath("//button[text()='CONTINUE AS GUEST']").click(); 101 | 102 | //Print the warning message (delay in shipment) 103 | String delayMsg = driver.findElementByXPath("//div[@class='message']").getText(); 104 | System.out.println("The message displayed is " + delayMsg); 105 | // Close all windows 106 | driver.quit(); 107 | 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /PepperFry.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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.ExpectedCondition; 20 | import org.openqa.selenium.support.ui.ExpectedConditions; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | 23 | public class PepperFry { 24 | 25 | public static void main(String[] args) throws InterruptedException, IOException { 26 | System.setProperty("webdriver.chrome.silentOutput", "true"); 27 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 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.pepperfry.com/"); 39 | // To maximize the browser 40 | driver.manage().window().maximize(); 41 | // implicitly wait 42 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 43 | 44 | //2) Mouseover on Furniture and click Office Chairs under Chairs 45 | WebElement eleFurniture = driver.findElementByXPath("(//a[text()='Furniture'])[1]"); 46 | Actions builder = new Actions(driver); 47 | builder.moveToElement(eleFurniture).perform(); 48 | Thread.sleep(1000); 49 | driver.findElementByXPath("(//a[text()='Office Chairs'])[1]").click(); 50 | WebDriverWait wait = new WebDriverWait(driver, 10); 51 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//div[@id='regPopUp']//a)[1]"))); 52 | driver.findElementByXPath("(//div[@id='regPopUp']//a)[1]").click(); 53 | Thread.sleep(2000); 54 | //3) click Executive Chairs 55 | driver.findElementByXPath("(//h5[text()='Executive Chairs'])[1]").click(); 56 | Thread.sleep(3000); 57 | 58 | //4) Change the minimum Height as 50 in under Dimensions 59 | WebElement height = driver.findElementByXPath("(//input[@class='clipFilterDimensionHeightValue'])[1]"); 60 | height.clear(); 61 | height.sendKeys("50",Keys.ENTER); 62 | Thread.sleep(3000); 63 | 64 | //5) Add "Poise Executive Chair in Black Colour" chair to Wishlist 65 | driver.findElementByXPath("//a[@data-productname='Poise Executive Chair in Black Colour']").click(); 66 | 67 | //6) Mouseover on Homeware and Click Pressure Cookers under Cookware 68 | WebElement eleHomeware = driver.findElementByXPath("(//a[text()='Homeware'])[1]"); 69 | Actions builder1= new Actions(driver); 70 | builder1.moveToElement(eleHomeware).perform(); 71 | Thread.sleep(1000); 72 | driver.findElementByXPath("(//a[text()='Pressure Cookers'])[1]").click(); 73 | Thread.sleep(3000); 74 | 75 | //7) Select Prestige as Brand 76 | driver.findElementByXPath("(//label[text()='Prestige'])[1]").click(); 77 | Thread.sleep(2000); 78 | 79 | //8) Select Capacity as 1-3 Ltr 80 | driver.findElementByXPath("//label[@for='capacity_db1_Ltr_-_3_Ltr']").click(); 81 | Thread.sleep(3000); 82 | 83 | //9) Add "Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr" to Wishlist 84 | driver.findElementByXPath("//a[@data-productname='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr']").click(); 85 | 86 | //10) Verify the number of items in Wishlist 87 | String noOfItems = driver.findElementByXPath("(//span[@class='count_alert'])[2]").getText(); 88 | if(noOfItems.equalsIgnoreCase("2")) { 89 | System.out.println("The no of items added in the wishlist is 2"); 90 | }else { 91 | System.out.println("The no of items added in the wishlist is not equal to 2"); 92 | } 93 | 94 | 95 | //11) Navigate to Wishlist 96 | driver.findElementByXPath("//div[@class='wishlist_bar']/a").click(); 97 | Thread.sleep(3000); 98 | 99 | driver.switchTo().activeElement(); 100 | //12) Move Pressure Cooker only to Cart from Wishlist 101 | //driver.executeScript("window.scrollBy(0, 750)"); 102 | //WebDriverWait wait1 = new WebDriverWait(driver, 30); 103 | //wait1.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//a[contains(text(),'Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr By')]/following::a[@class='addtocart_icon'])[2]"))); 104 | JavascriptExecutor js = (JavascriptExecutor) driver; 105 | 106 | WebElement addToCart = driver.findElementByXPath("(//a[contains(text(),'Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr By')]/following::a[@class='addtocart_icon'])[2]"); 107 | js.executeScript("arguments[0].click()", addToCart); 108 | 109 | Thread.sleep(2000); 110 | 111 | //13) Check for the availability for Pincode 600128 112 | driver.findElementByXPath("//input[@class='srvc_pin_text']").sendKeys("600061"); 113 | driver.findElementByXPath("//a[text()='Check']").click(); 114 | Thread.sleep(2000); 115 | //14) Click Proceed to Pay Securely 116 | driver.findElementByXPath("//a[contains(text(),'Proceed to pay securely')]").click(); 117 | Thread.sleep(2000); 118 | 119 | //15 Click Proceed to Pay 120 | driver.findElementByXPath("(//a[text()='PLACE ORDER'])[1]").click(); 121 | Thread.sleep(3000); 122 | 123 | //16) Capture the screenshot of the item under Order Item 124 | driver.findElementByXPath("//div[@id='ordersummary_accordian_header']").click(); 125 | Thread.sleep(2000); 126 | File src = driver.findElementByXPath("//div[@class='slick-list draggable']//li").getScreenshotAs(OutputType.FILE); 127 | File dst = new File("./snaps/snap1.png"); 128 | FileUtils.copyFile(src, dst); 129 | //17) Close the browser 130 | driver.quit(); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # selenium90days 2 | Coding on selenium 3 | -------------------------------------------------------------------------------- /Shiksha.java: -------------------------------------------------------------------------------- 1 | package first21Days; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.JavascriptExecutor; 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.DesiredCapabilities; 14 | import org.openqa.selenium.support.ui.Select; 15 | 16 | public class Shiksha { 17 | 18 | public static void main(String[] args) throws InterruptedException { 19 | 20 | // 1) Go to https://studyabroad.shiksha.com/ 21 | System.setProperty("webdriver.chrome.silentOutput", "true"); 22 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 23 | // disable the notifications 24 | 25 | ChromeOptions options = new ChromeOptions(); 26 | options.addArguments("--disable-notifications"); 27 | DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 28 | 29 | options.addArguments("--incognito"); 30 | capabilities.setCapability(ChromeOptions.CAPABILITY, options); 31 | // Launching Chrome Browser 32 | ChromeDriver driver = new ChromeDriver(options); 33 | // To Load the url 34 | driver.get("https://studyabroad.shiksha.com/"); 35 | // To maximize the browser 36 | driver.manage().window().maximize(); 37 | // implicitly wait 38 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 39 | JavascriptExecutor js = (JavascriptExecutor) driver; 40 | 41 | // 2) Mouse over on Colleges and click MS in Computer Science &Engg under MS 42 | // Colleges 43 | WebElement eleCollege = driver.findElementByXPath("(//label[text()='Colleges '])[1]"); 44 | Actions builder = new Actions(driver); 45 | builder.moveToElement(eleCollege).perform(); 46 | Thread.sleep(500); 47 | driver.findElementByXPath("//a[text()='MS in Computer Science &Engg']").click(); 48 | Thread.sleep(3000); 49 | 50 | // 3) Select GRE under Exam Accepted and Score 300 & Below 51 | driver.findElementByXPath("(//p[text()='GRE'])[1]").click(); 52 | Thread.sleep(1000); 53 | WebElement slctScore = driver.findElementByXPath("(//select[@class='score-select-field'])[1]"); 54 | Select score = new Select(slctScore); 55 | score.selectByVisibleText("300 & below"); 56 | Thread.sleep(2000); 57 | 58 | // 4) Max 10 Lakhs under 1st year Total fees, USA under countries 59 | driver.findElementByXPath("//span[@class='common-sprite']/preceding::p[contains(text(),'Max 10 Lakhs')]") 60 | .click(); 61 | Thread.sleep(3000); 62 | driver.findElementByXPath("//a[text()='USA']/ancestor::label/span").click(); 63 | Thread.sleep(3000); 64 | 65 | // 5) Select Sort By: Low to high 1st year total fees 66 | WebElement sortCategory = driver.findElementById("categorySorter"); 67 | Select category = new Select(sortCategory); 68 | category.selectByVisibleText("Low to high 1st year total fees"); 69 | Thread.sleep(3000); 70 | 71 | // 6) Click Add to compare of the College having least fees with Public 72 | // University, Scholarship and Accomadation 73 | List collegesList = driver 74 | .findElementsByXPath("//div[contains(@id,'categoryPageListing_tupleId')]"); 75 | int listSize = collegesList.size(); 76 | List colFee = new ArrayList(); 77 | // List tickMark = 78 | // driver.findElementsByXPath("(//div[contains(@id,'categoryPageListing_tupleId')])[1]//span[@class='tick-mark']"); 79 | for (int i = 1; i <= listSize; i++) { 80 | if (driver 81 | .findElementsByXPath( 82 | "(//div[contains(@id,'categoryPageListing_tupleId')])[" + i + "]//span[@class='tick-mark']") 83 | .size() == 3) { 84 | colFee.add(Double.parseDouble(driver 85 | .findElementByXPath("(//div[@class='detail-col flLt']/p[contains(text(),'Rs')])[" + i + "]") 86 | .getText().replaceAll("[^0-9\\s.]+|\\.(?!\\d)", ""))); 87 | } 88 | } 89 | Thread.sleep(1000); 90 | Collections.sort(colFee); 91 | driver.findElementByXPath("(//div[@class='detail-col flLt'])/p[contains(text(),'" + colFee.get(0) 92 | + "')]/ancestor::div[@class='clearwidth']/following-sibling::div[@class='compare-box flRt customInputs']//span") 93 | .click(); 94 | 95 | // 7) Select the first college under Compare with similar colleges 96 | driver.findElementByXPath("//a[text()=' Texas Southern University']").click(); 97 | Thread.sleep(500); 98 | 99 | // 8) Click on Compare College> 100 | driver.findElementByXPath("//strong[text()='Compare Colleges >']").click(); 101 | Thread.sleep(3000); 102 | 103 | // 9) Select When to Study as 2021 104 | driver.findElementByXPath("//strong[text()='2021']").click(); 105 | Thread.sleep(1000); 106 | 107 | // 10) Select Preferred Countries as USA 108 | WebElement preferredCountry = driver.findElementByXPath("//div[text()='Preferred Countries']"); 109 | js.executeScript("arguments[0].click()", preferredCountry); 110 | Thread.sleep(1000); 111 | driver.findElementByXPath("//div[@class='in-tab']//label[text()[normalize-space()='USA']]").click(); 112 | driver.findElementByXPath("//a[text()='ok']").click(); 113 | Thread.sleep(1000); 114 | 115 | // 11) Select Level of Study as Masters 116 | driver.findElementByXPath("//strong[text()='Masters']").click(); 117 | Thread.sleep(500); 118 | 119 | // 12) Select Preferred Course as MS 120 | WebElement preferredCourse = driver.findElementByXPath("//div[text()='Preferred Course']"); 121 | js.executeScript("arguments[0].click()", preferredCourse); 122 | Thread.sleep(500); 123 | driver.findElementByXPath("//li[text()='MS']").click(); 124 | Thread.sleep(1000); 125 | 126 | // 13) Select Specialization as "Computer Science & Engineering" 127 | WebElement preferredspl = driver.findElementByXPath("//div[text()='Preferred Specialisations']"); 128 | js.executeScript("arguments[0].click()", preferredspl); 129 | Thread.sleep(500); 130 | driver.findElementByXPath("//li[text()='Computer Science & Engineering']").click(); 131 | Thread.sleep(1000); 132 | 133 | // 14) Click on Sign Up 134 | driver.findElementByXPath("//a[@id='signup']").click(); 135 | Thread.sleep(2000); 136 | 137 | // 15) Print all the warning messages displayed on the screen for missed 138 | // mandatory fields 139 | List errorMsgs = driver 140 | .findElementsByXPath("//div[@class='input-helper']//div[contains(text(),'Please')]"); 141 | System.out.println("Error messages for mandatory fields are displayed below :"); 142 | for (int i = 0; i < errorMsgs.size(); i++) { 143 | String errorMsgText = errorMsgs.get(i).getText(); 144 | if (errorMsgText.length() > 0) { 145 | System.out.println(errorMsgText); 146 | } 147 | } 148 | driver.close(); 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /SnapDeal.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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.Action; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.remote.DesiredCapabilities; 14 | 15 | public class SnapDeal { 16 | 17 | public static void main(String[] args) throws InterruptedException { 18 | // 1) Go to https://www.snapdeal.com/ 19 | 20 | System.setProperty("webdriver.chrome.silentOutput", "true"); 21 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 22 | // disable the notifications 23 | 24 | ChromeOptions options = new ChromeOptions(); 25 | options.addArguments("--disable-notifications"); 26 | DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 27 | 28 | options.addArguments("--incognito"); 29 | capabilities.setCapability(ChromeOptions.CAPABILITY, options); 30 | // Launching Chrome Browser 31 | ChromeDriver driver = new ChromeDriver(options); 32 | // To Load the url 33 | driver.get("https://www.snapdeal.com/"); 34 | // To maximize the browser 35 | driver.manage().window().maximize(); 36 | // implicitly wait 37 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 38 | Actions builder = new Actions(driver); 39 | // ‎2) Mouse over on Toys, Kids' Fashion & more and click on Toys 40 | WebElement toysKids = driver.findElementByXPath("//span[contains(text(),'Toys, Kids')]"); 41 | 42 | builder.moveToElement(toysKids).perform(); 43 | 44 | // 3) Click Educational Toys in Toys & Games 45 | driver.findElementByXPath("//span[text()='Educational Toys']").click(); 46 | Thread.sleep(3000); 47 | // ‎4) Click the Customer Rating 4 star and Up 48 | driver.findElementByXPath("//label[@for='avgRating-4.0']").click(); 49 | Thread.sleep(2000); 50 | // 5) Click the offer as 40-50 51 | driver.findElementByXPath("//label[@for='discount-40%20-%2050']").click(); 52 | Thread.sleep(2000); 53 | // 6) Check the availability for the pincode 54 | driver.findElementByXPath("//input[@placeholder='Enter your pincode']").sendKeys("600061"); 55 | driver.findElementByXPath("//button[text()='Check']").click(); 56 | Thread.sleep(3000); 57 | // 7) Click the Quick View of the first product 58 | WebElement firstToyProduct = driver.findElementByXPath("(//p[@class='product-title'])[1]"); 59 | builder.moveToElement(firstToyProduct).perform(); 60 | ; 61 | driver.findElementByXPath("(//div[@class='clearfix row-disc']//div)[1]").click(); 62 | // 8) Click on View Details 63 | driver.findElementByXPath("//a[contains(text(),' view')]").click(); 64 | Thread.sleep(3000); 65 | 66 | // 9) Capture the Price of the Product and Delivery Charge 67 | String priceOfProduct = driver.findElementByXPath("//span[@class='payBlkBig']").getText(); 68 | System.out.println("The Price of the toy is " + priceOfProduct); 69 | int intPrice = Integer.parseInt(priceOfProduct); 70 | // System.out.println(intPrice); 71 | String deliveryChargeOfToy = driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 72 | System.out.println("The delivery charge of the toy is " + deliveryChargeOfToy.substring(4)); 73 | String reDeliveryCharge = deliveryChargeOfToy.replaceAll("[^0-9]", ""); 74 | // System.out.println("replaced delivery charge "+reDeliveryCharge); 75 | int intDeliveryCharge = Integer.parseInt(reDeliveryCharge); 76 | // System.out.println("delivery charge in int "+intDeliveryCharge); 77 | int totalPrice = intPrice + intDeliveryCharge; 78 | Thread.sleep(2000); 79 | 80 | // 10) Validate the You Pay amount matches the sum of (price+deliver charge) 81 | driver.findElementByXPath("//span[text()='add to cart']").click(); 82 | Thread.sleep(2000); 83 | String finalPrice = driver.findElementByXPath("(//span[@class='price'])[2]").getText(); 84 | System.out.println("The Price for the toy you pay finally is " + finalPrice); 85 | String reFinalPrice = finalPrice.replaceAll("[^0-9]", ""); 86 | int intFinalPrice = Integer.parseInt(reFinalPrice); 87 | if (intFinalPrice == totalPrice) { 88 | System.out.println("The price in the cart is equal to the sum of the price in the page "); 89 | } else { 90 | System.out.println("The price in the cart is not equal to the sum of the price in the page "); 91 | } 92 | 93 | // 11) Search for Sanitizer 94 | driver.findElementByXPath("//input[@id='inputValEnter']").sendKeys("Sanitizer"); 95 | driver.findElementByXPath("(//a[@data-labelname='sanitizer'])[1]").click(); 96 | Thread.sleep(3000); 97 | 98 | // 12) Click on Product "BioAyurveda Neem Power Hand Sanitizer" 99 | driver.findElementByXPath("(//p[contains(text(),'BioAyurveda Neem Power')])[1]").click(); 100 | Thread.sleep(3000); 101 | 102 | // 13) Capture the Price and Delivery Charge 103 | Set allWindows = driver.getWindowHandles(); 104 | List allList = new ArrayList(allWindows); 105 | driver.switchTo().window(allList.get(1)); 106 | String priceOfSanitizer = driver.findElementByXPath("//span[@class='payBlkBig']").getText(); 107 | System.out.println("The Price of the Sanitizer is " + priceOfSanitizer); 108 | int intSanitizerPrice = Integer.parseInt(priceOfSanitizer); 109 | 110 | String deliveryChargeOfSanitizer = driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 111 | System.out.println("The Delivery charge for the Sanitizer is " + deliveryChargeOfSanitizer.substring(4)); 112 | String reDeliveryChargeSanitizer = deliveryChargeOfSanitizer.replaceAll("[^0-9]", ""); 113 | // System.out.println("replaced delivery charge "+reDeliveryCharge); 114 | int intDeliveryChargeSanitizer = Integer.parseInt(reDeliveryChargeSanitizer); 115 | // System.out.println("delivery charge in int "+intDeliveryCharge); 116 | int totalPriceOfSanitizer = intSanitizerPrice + intDeliveryChargeSanitizer; 117 | System.out.println("the total price of sanitizer is " + totalPriceOfSanitizer); 118 | Thread.sleep(2000); 119 | 120 | // 14) Click on Add to Cart 121 | driver.findElementByXPath("(//span[text()='ADD TO CART'])[1]").click(); 122 | Thread.sleep(3000); 123 | 124 | // 15) Click on Cart 125 | driver.findElementByXPath("//i[@class='sd-icon sd-icon-cart-icon-white-2']").click(); 126 | Thread.sleep(3000); 127 | 128 | // 16) Validate the Proceed to Pay matches the total amount of both the products 129 | 130 | String priceOfBothProducts = driver.findElementByXPath("//input[@class='btn btn-xl rippleWhite cart-button']") 131 | .getAttribute("value"); 132 | System.out.println("The price of both items is " + priceOfBothProducts.substring(15)); 133 | String rePriceOfBoth = priceOfBothProducts.replaceAll("[^0-9]", ""); 134 | int intPriceOfBoth = Integer.parseInt(rePriceOfBoth); 135 | int intTotalOfBothProducts = totalPrice + totalPriceOfSanitizer; 136 | if (intPriceOfBoth == intTotalOfBothProducts) { 137 | System.out.println("The Price in the cart is same as the sum of both products price"); 138 | } else { 139 | System.out.println("The Price in the cart is not same as the sum of both products price"); 140 | 141 | } 142 | // 17) Close all the windows 143 | driver.quit(); 144 | 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /Zalando.java: -------------------------------------------------------------------------------- 1 | package first21Days; 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.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.DesiredCapabilities; 15 | import org.openqa.selenium.support.ui.ExpectedConditions; 16 | import org.openqa.selenium.support.ui.WebDriverWait; 17 | 18 | public class Zalando { 19 | 20 | public static void main(String[] args) throws InterruptedException { 21 | // 1) Go to https://www.zalando.com/ 22 | 23 | System.setProperty("webdriver.chrome.silentOutput", "true"); 24 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 25 | // disable the notifications 26 | 27 | ChromeOptions options = new ChromeOptions(); 28 | options.addArguments("--disable-notifications"); 29 | DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 30 | 31 | options.addArguments("--incognito"); 32 | capabilities.setCapability(ChromeOptions.CAPABILITY, options); 33 | // Launching Chrome Browser 34 | ChromeDriver driver = new ChromeDriver(options); 35 | // To Load the url 36 | driver.get("https://www.zalando.com/"); 37 | 38 | // 2) Get the Alert text and print it 39 | Alert alert = driver.switchTo().alert(); 40 | String alertText = alert.getText(); 41 | System.out.println("The Alert text is : " + alertText); 42 | 43 | // 3) Close the Alert box and click on Zalando.uk 44 | alert.accept(); 45 | 46 | // To maximize the browser 47 | driver.manage().window().maximize(); 48 | 49 | // implicitly wait 50 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 51 | WebDriverWait wait = new WebDriverWait(driver, 30); 52 | JavascriptExecutor js = (JavascriptExecutor) driver; 53 | Actions actions = new Actions(driver); 54 | 55 | driver.findElementByXPath("//a[text()='Zalando.uk']").click(); 56 | Thread.sleep(3000); 57 | // driver.findElementByXPath("//div[@class='uc-btn-footer-container']").click(); 58 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//button[@id='uc-btn-accept-banner']"))); 59 | WebElement eleThatsOk = driver.findElementByXPath("//button[text()[normalize-space()='That’s OK']]"); 60 | js.executeScript("arguments[0].click()", eleThatsOk); 61 | Thread.sleep(2000); 62 | 63 | // 4) Click Women--> Clothing and click Coat 64 | driver.findElementByXPath("(//span[text()='Women'])[1]").click(); 65 | Thread.sleep(2000); 66 | WebElement eleClothing = driver.findElementByXPath("//span[text()='Clothing']"); 67 | actions.moveToElement(eleClothing).perform(); 68 | driver.findElementByXPath("//span[text()='Coats']").click(); 69 | Thread.sleep(3000); 70 | 71 | // 5) Choose Material as cotton (100%) and Length as thigh-length 72 | driver.findElementByXPath("//span[text()='Length']").click(); 73 | driver.findElementByXPath("//span[text()='thigh-length']").click(); 74 | WebElement eleLengthSave = driver.findElementByXPath("//button[text()='Save']"); 75 | js.executeScript("arguments[0].click()", eleLengthSave); 76 | 77 | Thread.sleep(2000); 78 | driver.findElementByXPath("//span[text()='Material']").click(); 79 | driver.findElementByXPath("//span[text()='cotton (100%)']").click(); 80 | WebElement eleMaterialSave = driver.findElementByXPath("//button[text()='Save']"); 81 | js.executeScript("arguments[0].click()", eleMaterialSave); 82 | 83 | Thread.sleep(3000); 84 | 85 | // 6) Click on Q/S designed by MANTEL - Parka coat 86 | driver.findElementByXPath("//div[text()='MANTEL - Parka - navy']").click(); 87 | Thread.sleep(2000); 88 | 89 | // 7) Check the availability for Color as Olive and Size as 'M' 90 | driver.findElementByXPath("(//img[@alt='olive'])[2]").click(); 91 | Thread.sleep(1000); 92 | 93 | // 8) If the previous preference is not available, check availability for Color Navy and Size 'M' 94 | if (driver.findElementByXPath("//button[@id='picker-trigger']").isEnabled() == true || driver 95 | .findElementByXPath("//h2[text()='Out of stock']").getText().equalsIgnoreCase("Out of stock")) { 96 | driver.findElementByXPath("(//img[@alt='navy'])[2]").click(); 97 | driver.findElementByXPath("//span[text()='Choose your size']").click(); 98 | driver.findElementByXPath("//span[text()='M']").click(); 99 | } else { 100 | driver.findElementByXPath("//span[text()='Choose your size']").click(); 101 | if (driver.findElementByXPath("//span[text()='M']").isEnabled() == true) { 102 | driver.findElementByXPath("//span[text()='M']").click(); 103 | } else { 104 | System.out.println("The size M not available"); 105 | } 106 | } 107 | 108 | // 9) Add to bag only if Standard Delivery is free 109 | if (driver.findElementByXPath("(//span[@class='AtOZbZ'])[2]").getText().equalsIgnoreCase("Free")) { 110 | driver.findElementByXPath("//button[@aria-label='Add to bag']").click(); 111 | Thread.sleep(2000); 112 | } else { 113 | System.out.println("The standard delivery is not free so not adding to cart."); 114 | } 115 | // 10) Mouse over on Your Bag and Click on "Go to Bag" 116 | WebElement addToCart = driver.findElementByXPath("//a[@class='z-navicat-header_navToolItemLink']"); 117 | actions.moveToElement(addToCart).perform(); 118 | driver.findElementByXPath("//div[text()='Go to bag']").click(); 119 | Thread.sleep(2000); 120 | 121 | // 11) Capture the Estimated Deliver Date and print 122 | String strEstDeliverDate = driver.findElementByXPath("//div[@data-id='delivery-estimation']//span").getText(); 123 | System.out.println("The Estimated Deliver Date for the Coat is : " + strEstDeliverDate); 124 | 125 | // 12) Mouse over on FREE DELIVERY & RETURNS*, get the tool tip text and print 126 | WebElement eleFreeDelivery = driver 127 | .findElementByXPath("(//span[@class='z-navicat-header-uspBar_message-split_styled'])[2]"); 128 | actions.moveToElement(eleFreeDelivery).perform(); 129 | String strToolTip = eleFreeDelivery.getAttribute("title"); 130 | System.out.println("The Tool Tip of free Delivery & Returns is : " + strToolTip); 131 | 132 | // 13) Click on FREE DELIVERY & RETURNS 133 | eleFreeDelivery.click(); 134 | Thread.sleep(3000); 135 | 136 | // 14) Click on Start chat in the Start chat and go to the new window 137 | if (driver.findElementByXPath("//span[text()='Start chat']").isEnabled() == true) { 138 | driver.findElementByXPath("//span[text()='Start chat']").click(); 139 | } else { 140 | System.out.println("The chat box not enabled"); 141 | } 142 | 143 | // 15) Enter you first name and a dummy email and click Start Chat 144 | Set allWindows = driver.getWindowHandles(); 145 | List allList = new ArrayList(allWindows); 146 | driver.switchTo().window(allList.get(1)); 147 | driver.findElementByXPath("//input[@id='prechat_customer_name_id']").sendKeys("Ashwath"); 148 | driver.findElementByXPath("//input[@id='prechat_customer_email_id']").sendKeys("Ashu@ddd.com"); 149 | driver.findElementByXPath("//button[@id='prechat_submit']").click(); 150 | Thread.sleep(5000); 151 | 152 | // 16) Type Hi, click Send and print thr reply message and close the chat window. 153 | driver.findElementByXPath("//textarea[@id='liveAgentChatTextArea']").sendKeys("Hi"); 154 | driver.findElementByXPath("//button[text()='Send']").click(); 155 | String strReply = driver.findElementByXPath("//span[@class='client']/following-sibling::span[1]").getText(); 156 | System.out.println("The Reply message is : " + strReply); 157 | 158 | driver.quit(); 159 | 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /output.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavithra72/selenium90days/23398bb75bfad6eadee73052b64f51e22ee0d999/output.xlsx -------------------------------------------------------------------------------- /snap1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavithra72/selenium90days/23398bb75bfad6eadee73052b64f51e22ee0d999/snap1.png --------------------------------------------------------------------------------