List of usage examples for org.openqa.selenium By linkText
public static By linkText(String linkText)
From source file:com.java.AppTestType_18_11_2015.java
public void MYOPERATION(WebDriver driver, String fieldText, String value) { //It is used where framework actions doesn't work //We need to proviede SND<Text to enter> in the value fields to perform "Sendkeys" //We need to proviede CLK in the value fields to perform "Click" try {/*w w w . j a va 2s.c o m*/ driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); String f = fieldText; String oper = value; String attribute = f.substring(0, 3); String locator = f.substring(3, f.length()); String operation = oper.substring(0, 3); String val = oper.substring(3, oper.length()); if (operation.equalsIgnoreCase("CLK")) { switch (attribute) { case "IDI": driver.findElement(By.id(locator)).click(); resultDetails.setFlag(true); break; case "XPH": driver.findElement(By.xpath(locator)).click(); resultDetails.setFlag(true); break; case "LNK": driver.findElement(By.linkText(locator)).click(); resultDetails.setFlag(true); break; case "PLK": driver.findElement(By.partialLinkText(locator)).click(); resultDetails.setFlag(true); break; default: System.out.println("Invalid Locator attribute"); break; } } else if (operation.equalsIgnoreCase("SND")) { switch (attribute) { case "IDI": driver.findElement(By.id(locator)).clear(); driver.findElement(By.id(locator)).sendKeys(val); resultDetails.setFlag(true); break; case "XPH": driver.findElement(By.xpath(locator)).clear(); driver.findElement(By.xpath(locator)).sendKeys(val); resultDetails.setFlag(true); break; case "LNK": driver.findElement(By.linkText(locator)).clear(); driver.findElement(By.linkText(locator)).sendKeys(val); resultDetails.setFlag(true); break; default: System.out.println("Invalid Locator attribute"); break; } } else if (operation.equalsIgnoreCase("MTE")) { switch (attribute) { case "IDI": new Actions(driver).moveToElement(driver.findElement(By.id(locator))).perform(); break; case "XPH": new Actions(driver).moveToElement(driver.findElement(By.xpath(locator))).perform(); resultDetails.setFlag(true); break; case "LNK": new Actions(driver).moveToElement(driver.findElement(By.linkText(locator))).perform(); resultDetails.setFlag(true); break; default: System.out.println("Invalid Locator attribute"); break; } } else if (operation.equalsIgnoreCase("SEL")) { switch (attribute) { case "XPH": new Select(driver.findElement(By.xpath(locator))).selectByVisibleText(val); resultDetails.setFlag(true); break; } } } catch (Exception e) { resultDetails.setFlag(false); e.printStackTrace(); } }
From source file:com.java.AppTestType_18_11_2015.java
public void SIGNIN(WebDriver driver, String fieldText, String value) { try {/* w w w . j a v a2 s . c o m*/ try { WebDriverWait wait = new WebDriverWait(driver, 20); // wait.until(ExpectedConditions.titleIs("Used Equipment Sales | Buy & Sell Online | Ritchie Bros. EquipmentOne")); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().deleteAllCookies(); //driver.findElement(By.linkText("Sign In")).click(); driver.findElement(By.name("josso_username")).clear(); driver.findElement(By.name("josso_username")).sendKeys(fieldText); driver.findElement(By.name("josso_password")).clear(); driver.findElement(By.name("josso_password")).sendKeys("Equipment1$"); try { driver.findElement(By.xpath("//*[@value='SIGN IN']")).click(); } catch (Exception elementnotfoundexException) { driver.findElement(By.xpath("//button[text()='SIGN IN']")).click(); } System.out.println("size is :" + driver.findElements(By.id("iduser")).size()); if (driver.findElements(By.id("iduser")).size() > 0) { System.out.println("1111111111"); driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); if (driver.findElements(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']")) .size() > 0) { driver.findElement(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']")) .click(); driver.findElement( By.xpath("//*[@class='btn btn-primary btn-group-justified' and @type='submit']")) .click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); // driver.findElement(By.xpath("//input[@value='Go to EquipmentOne']")).click(); // wait.until(ExpectedConditions.titleIs("Used Equipment Sales | Buy & Sell Online | Ritchie Bros. EquipmentOne")); } //to confirm successful sign in as valid user,verifying the name displayed next to "Hello" text if (driver.findElement(By.id("iduser")).getText().equalsIgnoreCase(value)) System.out.println("Successfully Logged in"); else { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.findElement(By.linkText("Sign Out")).click(); wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("josso_password"))); driver.findElement(By.name("josso_username")).clear(); driver.findElement(By.name("josso_username")).sendKeys(fieldText); driver.findElement(By.name("josso_password")).clear(); driver.findElement(By.name("josso_password")).sendKeys("Equipment1$"); driver.findElement(By.xpath("//*[@value='SIGN IN']")).click(); wait.until(ExpectedConditions.elementToBeClickable(By.id("iduser"))); //agree terms-This piece of code is to verify agree terms checkbox after re logging(not logged in as the valid user) driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); if (driver.findElements(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']")) .size() > 0) { driver.findElement(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']")) .click(); driver.findElement(By .xpath("//*[@class='btn btn-primary btn-group-justified' and @type='submit']")) .click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); // driver.findElement(By.xpath("//input[@value='Go to EquipmentOne']")).click(); // wait.until(ExpectedConditions.titleIs("Used Equipment Sales | Buy & Sell Online | Ritchie Bros. EquipmentOne")); } } resultDetails.setFlag(true); } } //This catch is used to catch the error "You are NOT authorized to access Site" in E1 Login// ///////////////////////////////////// catch (Exception e1) { driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); if (driver.getPageSource().contains("You are NOT authorized to access Site")) { System.out.println("You are NOT authorized to access Site error message is displayed"); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.navigate().to("http://e1.dev.assetnation.com"); SIGNIN(driver, fieldText, value); } } } catch (Exception e) { e.printStackTrace(); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void SIGNOUT(WebDriver driver) { driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); try {//from www. j av a2s . co m String url = driver.getCurrentUrl(); String url2 = url.toUpperCase(); //according to new to changes the following is not needed /*if(url2.contains("LISTINGID")) { driver.findElement(By.id("uname")).click(); Thread.sleep(2000); }*/ driver.findElement(By.linkText("Sign Out")).click(); if (driver.findElement(By.linkText("Sign In")).isDisplayed()) resultDetails.setFlag(true); } catch (Exception e) { e.printStackTrace(); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void WAITFORTHIS(WebDriver driver, String fieldText, String value) { //Used to verify the text in any specific Loctor or Message //<XPH or LNK or IDI or TXT or MSG><Locator> in fieldText //Time in milliseconds in Value try {/*w w w. ja v a 2 s. c o m*/ String f = fieldText; String time = value; String locatorType = f.substring(0, 3); String locatorValue = f.substring(3, f.length()); int timevalue = Integer.parseInt(time); driver.manage().timeouts().implicitlyWait(timevalue, TimeUnit.MILLISECONDS); if (locatorType.equalsIgnoreCase("XPH")) { if (driver.findElements(By.xpath(locatorValue)).size() > 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("LNK")) { if (driver.findElements(By.linkText(locatorValue)).size() > 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) { if (driver.findElements(By.id(locatorValue)).size() > 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("MSG")) { int j = 0; int t = timevalue / 1000; for (int i = 0; i < t; i++) { if (driver.findElement(By.xpath("//*[contains(text(),'" + locatorValue + "')]")) .isDisplayed()) { j = 1; break; } Thread.sleep(1000); } if (j == 1) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("PLK")) { if (driver.findElements(By.partialLinkText(locatorValue)).size() > 0) resultDetails.setFlag(true); } } catch (Exception e) { resultDetails.setErrorMessage(fieldText + "Locator Not Found"); resultDetails.setFlag(false); e.printStackTrace(); } }
From source file:com.java.AppTestType_18_11_2015.java
public void VERIFYTHIS(WebDriver driver, String fieldText, String value) { //Used to verify the text in any specific Loctor or Message //<XPH or LNK or IDI or TXT><Locator> or MSG in fieldText //Text or Message to be verified in Value try {/*from ww w . j av a2s . c o m*/ driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS); String f = fieldText; String val = value; String locatorType = f.substring(0, 3); String locatorValue = f.substring(3, f.length()); if (locatorType.equalsIgnoreCase("XPH")) { System.out.println(driver.findElement(By.xpath(locatorValue)).getText()); if (driver.findElement(By.xpath(locatorValue)).getText().equalsIgnoreCase(val)) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("LNK")) { if (driver.findElement(By.linkText(locatorValue)).getText().equalsIgnoreCase(val)) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) { if (driver.findElement(By.id(locatorValue)).getText().equalsIgnoreCase(val)) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("MSG")) { int j = 0; for (int i = 0; i < 20; i++) { if (driver.findElement(By.xpath("//*[contains(text(),'" + val + "')]")).isDisplayed()) { j = 1; break; } Thread.sleep(1000); } if (j == 1) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("TTL")) { int j = 0; for (int i = 0; i < 20; i++) { if (driver.getTitle().equalsIgnoreCase(val)) { j = 1; break; } Thread.sleep(1000); } if (j == 1) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("URL")) { int j = 0; for (int i = 0; i < 20; i++) { if (driver.getCurrentUrl().equalsIgnoreCase(val)) { j = 1; break; } Thread.sleep(1000); } if (j == 1) resultDetails.setFlag(true); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage( fieldText + " Text is not matching with that of the locator (or) the locator not found"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void EXACTBIDFROMWATCHINGPAGE(WebDriver driver) { try {/*from www . j a va 2s . c o m*/ driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings"); WebDriverWait wait = new WebDriverWait(driver, 25); Thread.sleep(1000); //navigation to next page driver.findElement(By.linkText("2")).click(); //Thread.sleep(5000) wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]"))); //clicking on first binocular icon which is not yet watching driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("(//a[text()='MyONE '])[2]"))); driver.findElement(By.xpath("(//a[text()='MyONE '])[2]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.partialLinkText("Watching"))); driver.findElement(By.partialLinkText("Watching")).click(); if (wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]"))) .isDisplayed()) { driver.findElement(By.xpath("(//*[@type='radio' and @value='Exact Bid'])[2]")).click(); Thread.sleep(4000); driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click(); BIDDING_IN_LISTINGDETAILSPAGE(driver); resultDetails.setFlag(true); } else { System.out.println("there is no place a bid button in watchlist section"); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Listing is not available or Closed"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void MAXBIDFROMWATCHINGPAGE(WebDriver driver) { try {// w w w .jav a 2s.com driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings"); WebDriverWait wait = new WebDriverWait(driver, 25); Thread.sleep(1000); //navigation to next page driver.findElement(By.linkText("2")).click(); //Thread.sleep(5000) wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]"))); //clicking on first binocular icon which is not yet watching driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("(//a[text()='MyONE '])[2]"))); driver.findElement(By.xpath("(//a[text()='MyONE '])[2]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.partialLinkText("Watching"))); driver.findElement(By.partialLinkText("Watching")).click(); if (wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]"))) .isDisplayed()) { driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click(); BIDDING_IN_LISTINGDETAILSPAGE(driver); resultDetails.setFlag(true); } else { System.out.println("there is no 'place a bid button' in watchlist section"); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Listing is not available or Closed"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void VISIBLE(WebDriver driver, String fieldText, String value) { //To verify whetheer a locator is visible //FieldText---Locator //value----Time in ms try {//from w w w. ja v a 2s.c o m String f = fieldText; String locatorType = f.substring(0, 3); String locatorValue = f.substring(3, f.length()); String val1 = value; int val = Integer.parseInt(val1); driver.manage().timeouts().implicitlyWait(val, TimeUnit.MILLISECONDS); if (locatorType.equalsIgnoreCase("XPH")) { //System.out.println(driver.findElement(By.xpath(locatorValue)).getText()); if (driver.findElement(By.xpath(locatorValue)).isDisplayed()) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("LNK")) { if (driver.findElement(By.linkText(locatorValue)).isDisplayed()) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) { if (driver.findElement(By.id(locatorValue)).isDisplayed()) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("MSG")) { if (driver.findElement(By.xpath("//*[contains(text(),'" + locatorValue + "')]")).isDisplayed()) resultDetails.setFlag(true); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Element is Not Visible"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void NOTVISIBLE(WebDriver driver, String fieldText, String value) { //To verify whetheer a locator is NOT visible //FieldText---Locator //value----Time in ms try {/*w w w. ja v a 2s. co m*/ String f = fieldText; String locatorType = f.substring(0, 3); String locatorValue = f.substring(3, f.length()); String val1 = value; int val = Integer.parseInt(val1); driver.manage().timeouts().implicitlyWait(val, TimeUnit.MILLISECONDS); if (locatorType.equalsIgnoreCase("XPH")) { //System.out.println(driver.findElement(By.xpath(locatorValue)).getText()); if (!driver.findElement(By.xpath(locatorValue)).isDisplayed()) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("LNK")) { if (!driver.findElement(By.linkText(locatorValue)).isDisplayed()) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) { if (!driver.findElement(By.id(locatorValue)).isDisplayed()) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("MSG")) { if (!driver.findElement(By.xpath("//*[contains(text(),'" + locatorValue + "')]")).isDisplayed()) resultDetails.setFlag(true); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Element is Visible"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void VERIFYNOT(WebDriver driver, String fieldText, String value) { //To verify that the locator doesn't exist //FieldText---Locator //value----Time in ms //Give lesser Time like 2000,or else the execution will wait that much time try {/*from w w w. j a v a 2 s . c om*/ String f = fieldText; String time = value; String locatorType = f.substring(0, 3); String locatorValue = f.substring(3, f.length()); int timevalue = Integer.parseInt(time); driver.manage().timeouts().implicitlyWait(timevalue, TimeUnit.MILLISECONDS); if (locatorType.equalsIgnoreCase("XPH")) { if (driver.findElements(By.xpath(locatorValue)).size() == 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("LNK")) { if (driver.findElements(By.linkText(locatorValue)).size() == 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) { if (driver.findElements(By.id(locatorValue)).size() == 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("MSG")) { int j = 0; int t = timevalue / 1000; for (int i = 0; i < t; i++) { if (driver.findElements(By.xpath("//*[contains(text(),'" + locatorValue + "')]")).size() == 0) { j = 1; break; } Thread.sleep(1000); } if (j == 1) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("PLK")) { if (driver.findElements(By.partialLinkText(locatorValue)).size() == 0) resultDetails.setFlag(true); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Element is Present"); resultDetails.setFlag(false); } }