List of usage examples for org.openqa.selenium By xpath
public static By xpath(String xpathExpression)
From source file:Practice01.java
public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); // Open Website driver.get("https://enterprise-demo.orangehrmlive.com/auth/login"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Type Username driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("Admin"); // Type Password driver.findElement(By.cssSelector("#txtPassword")).sendKeys("admin"); // Click on Login driver.findElement(By.id("btnLogin")).click(); // Click on PIM driver.findElement(By.id("menu_pim_viewPimModule")).click(); // Click Add Employee driver.findElement(By.xpath("//a[@id='menu_pim_addEmployee']")).click(); // DateFormat dateFormat = new SimpleDateFormat("ddhhss"); // Date date = new Date(); // String date1 = dateFormat.format(date); // String userName = "John"+date1; // String username1= "Smith"+date1; // Type First name driver.findElement(By.id("firstName")).sendKeys("John"); // Type Last name driver.findElement(By.id("lastName")).sendKeys("Smith"); Random random = new Random(); int eID = random.nextInt(1000); // Click on Location driver.findElement(By.id("employeeId")).clear(); driver.findElement(By.id("employeeId")).sendKeys("" + eID); // Click on/*ww w. j ava 2 s .co m*/ WebElement location_dd = driver.findElement(By.xpath("//select[@id='location']")); Select location = new Select(location_dd); location.selectByIndex(9); // Click Save driver.findElement(By.id("btnSave")).click(); // Click on edit driver.findElement(By.xpath("//input[@value='Edit']")).click(); // Click on licences expiry driver.findElement(By.id("personal_txtLicExpDate")).click(); // Select date driver.findElement(By.xpath("html/body/div[4]/table/tbody/tr[5]/td[2]/a")).click(); // Click on marital box driver.findElement(By.id("personal_cmbMarital")).click(); // Click on married driver.findElement(By.xpath("//select[@name='personal[cmbMarital]']/option[3]")).click(); // Click on Dob box driver.findElement(By.id("personal_DOB")).click(); //click month box Select month_dd = new Select(driver.findElement(By.xpath("//div[@class='ui-datepicker-title']/select[1]"))); month_dd.selectByVisibleText("Jul"); // Select Year Select year_dd = new Select(driver.findElement(By.xpath("//div/select[2]"))); year_dd.selectByIndex(35); // Click on Date driver.findElement(By.xpath("//table/tbody/tr[4]/td[4]/a")).click(); // Click Save driver.findElement(By.id("btnSave")).click(); // Verify Successfully Saved Message //Assert Assert.assertTrue("Successfully Saved", driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).isEnabled()); System.out.println("Successfully Saved"); //assert1 // String expectedText = "Successfully Saved"; // String actualText = driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).getText(); // Assert.assertEquals(expectedText,actualText); // Click Employee List driver.findElement(By.id("menu_pim_viewEmployeeList")).click(); // Thread.sleep(3000); // //click on emp name // driver.findElement(By.xpath("//input[@id='empsearch_employee_name_empName']")).sendKeys(userName + username1); // // Type Employee ID // driver.findElement(By.id("empsearch_id")).sendKeys(" "+eID); // // Clear Employee ID // driver.findElement(By.id("empsearch_id")).clear(); Thread.sleep(2000); // Search Emp by ID driver.findElement(By.id("empsearch_id")).sendKeys("" + eID); // Search Employee By ID // driver.findElement(By.id("searchBtn")).click(); Thread.sleep(2000); driver.findElement(By.id("searchBtn")).click(); //Assert Assert.assertTrue("John", driver.findElement(By.xpath("//tbody/tr/td[3]/a")).isEnabled()); System.out.println("John"); // }
From source file:$.CompareModelsPage.java
License:Apache License
public List<ModelSpecs> compareModels(String... models) { CondidateBlock condidateBlock;//w w w .j a v a 2 s . c o m List<ModelSpecs> modelSpecs = new ArrayList<>(); ModelSpecs modelSpec; for (int index = 0; index < models.length; index++) { modelSpec = new ModelSpecs(); condidateBlock = condidateBlocks.get(index); condidateBlock.sendKeysToInputField(models[index]); condidateBlock.getFirstPhone(); for (ModelSpecs.SpecType type : ModelSpecs.SpecType.values()) { ExtendedWebElement spec = findExtendedWebElement(By.xpath( String.format("//tr[.//a[text()='%s']]//td[@class='nfo'][%d]", type.getType(), index + 1))); modelSpec.setToModelSpecsMap(type, spec.getText()); } modelSpecs.add(modelSpec); } return modelSpecs; }
From source file:$.RegisterFT.java
License:Apache License
@Test public void inputInValidateValue() { s.open("/register"); s.click(By.id("submit_btn")); assertThat(s.getText(By.xpath("//fieldset/div/div/span"))).isEqualTo(""); }//from w w w .ja v a 2 s . c om
From source file:$.TaskGuiFT.java
License:Apache License
@Test public void inputInValidateValue() { s.open("/task/"); s.click(By.linkText("")); s.click(By.id("submit_btn")); assertThat(s.getText(By.xpath("//fieldset/div/div/span"))).isEqualTo(""); }/*w ww . j a va 2s .c om*/
From source file:Actions.HTTP_CODE_VERIFY.java
public boolean HTTP_CODES(String code) //this function asserts that http code is not displayed... { List<WebElement> Elements = driver.findElements(By.xpath("//*[contains(text()," + "'" + code + "'" + ")]")); int elementNo = Elements.size(); boolean act = (elementNo == 0); return (act); }
From source file:administrationedit.addCompany.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/user/updateCompanySettings"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); // Input name String nameComp = faker.company().name(); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys(nameComp); // Input address String addressComp = faker.address().fullAddress(); driver.findElement(By.id("address")).clear(); driver.findElement(By.id("address")).sendKeys(addressComp); // Input city String cityComp = faker.address().city(); driver.findElement(By.id("city")).clear(); driver.findElement(By.id("city")).sendKeys(cityComp); // Input postal code String postalCodeComp = faker.address().zipCode(); driver.findElement(By.id("postalCode")).clear(); driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp); // Country/*from w ww . j a v a 2 s . com*/ Select countryComp = new Select(driver.findElement(By.id("country"))); int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1; countryComp.selectByIndex(coutryCompInt); // Email String emailComp = faker.internet().emailAddress(); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys(emailComp); // Phone String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("phone")).clear(); driver.findElement(By.id("phone")).sendKeys(phoneComp); // Mobile String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", ""); driver.findElement(By.id("mobilePhone")).clear(); driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp); // Fax String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("fax")).clear(); driver.findElement(By.id("fax")).sendKeys(faxComp); // OIB String oibComp = faker.idNumber().validSvSeSsn(); driver.findElement(By.id("oib")).clear(); driver.findElement(By.id("oib")).sendKeys(oibComp); // VatID String vatComp = faker.idNumber().validSvSeSsn(); driver.findElement(By.id("vatId")).clear(); driver.findElement(By.id("vatId")).sendKeys(vatComp); // Id code String idCodeComp = faker.idNumber().valid(); driver.findElement(By.id("idCode")).clear(); driver.findElement(By.id("idCode")).sendKeys(idCodeComp); // MBS String mbsComp = faker.number().digits(15); driver.findElement(By.id("mbs")).clear(); driver.findElement(By.id("mbs")).sendKeys(mbsComp); // ID number String idNumComp = faker.number().digits(15); driver.findElement(By.id("identificationNumber")).clear(); driver.findElement(By.id("identificationNumber")).sendKeys(idNumComp); // IBAN String ibanComp = faker.finance().iban(); driver.findElement(By.id("iban")).clear(); driver.findElement(By.id("iban")).sendKeys(ibanComp); // Swift String swiftComp = faker.finance().bic(); driver.findElement(By.id("swift")).clear(); driver.findElement(By.id("swift")).sendKeys(swiftComp); //Bank name String bankNameComp = faker.name().name(); driver.findElement(By.id("bankName")).clear(); driver.findElement(By.id("bankName")).sendKeys(bankNameComp); // Bank address String bankAddressComp = faker.address().fullAddress(); driver.findElement(By.id("bankAddress")).clear(); driver.findElement(By.id("bankAddress")).sendKeys(bankAddressComp); // Bank city String bankCityComp = faker.address().city(); driver.findElement(By.id("bankCity")).clear(); driver.findElement(By.id("bankCity")).sendKeys(bankCityComp); // Bank postal code String bankPostalCodeComp = faker.address().zipCode(); driver.findElement(By.id("bankPostalCode")).clear(); driver.findElement(By.id("bankPostalCode")).sendKeys(bankPostalCodeComp); // Bank country Select bankCountryComp = new Select(driver.findElement(By.id("bankCountry"))); int bankCoutryCompInt = r.nextInt(bankCountryComp.getOptions().size()) + 1; bankCountryComp.selectByIndex(bankCoutryCompInt); // Social String socialTW = faker.internet().url(); String socialFB = faker.internet().url(); driver.findElement(By.id("twitterUsername")).clear(); driver.findElement(By.id("facebookID")).clear(); driver.findElement(By.id("twitterUsername")).sendKeys(socialTW); driver.findElement(By.id("facebookID")).sendKeys(socialFB); // SAVE driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[26]/div/button")) .click(); }
From source file:administrationedit.addOffice.java
public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); String[] city = { "Rijeka", "Pula", "Pore?", "Rovinj", "Umag", "Novigrad", "Vrsar", "Pazin", "Motovun", "Medulin", "Faana", "Vodnjan", "Opatija", "Krk", "Punat", "Baka", "Njivice", "Labin", "Rabac", "Plomin", "I?ii", "Ika", "Malinska", "Njivice", "Omialj", "Dramalj", "Crikvenica", "Selce", "Cres", "Rab", "Novi Vinodolski", "Povile", "iii", "Vodice", "Pinezii", "Lovran", "Medveja", "shanghai", "sao paulo", "kinshasa", "cairo", "peking", "london", "bogota", "dhaka", "rio de janeiro", "santiago", "toronto", "sydney", "wuhan", "chongqing", "xian", "chengdu", "alexandria", "tianjin", "melbourne", "abidjan", "shenyang", "berlin", "montreal", "harbin", "guangzhou", "madrid", "nanjing", "kabul", "luanda", "addis abeba", "taiyuan", "salvador", "changchun", "gizeh", "fortaleza", "cali", "belo horizonte", "brasilia", "santo domingo", "paris", "jinan", "tangshan", "dalian", "medellin", "algiers", "accra", "guayaquil", "jilin", "hangzhou", "nanchang", "conakry", "brisbane", "vancouver", "minsk", "hamburg", "curitiba", "qingdao", "manaus", "xinyang", "barcelona", "vienna", "urumqi", "recife", "kumasi", "perth", "cordoba", "lanzhou", "belem", "fushun", "quito", "luoyang", "hefei", "barranquilla", "lubumbashi", "porto alegre", "handan", "suzhou", "khulna", "douala", "yaounde", "munich", "rosario", "anshan", "xuzhou", "fuzhou", "guiyang", "goiania", "guarulhos", "prague", "dubai", "baku", "brazzaville", "wuxi", "yerevan", "copenhagen", "adelaide", "sofia", "datong", "tbilisi", "xianyang", "campinas", "ouagadougou", "huainan", "kunming", "brussels", "shenzhen", "nova iguacu", "rongcheng", "baoding", "benxi", "birmingham", "mendoza", "cologne", "calgary", "maceio", "cartagena", "changzhou", "sao goncalo", "sao luis", "huaibei", "cochabamba", "pingdingshan", "qiqihar", "mbuji-mayi", "ottawa", "wenzhou", "tucuman", "edmonton", "duque de caxias", "la paz", "nanning", "marseille", "anyang", "hohhot", "valencia", "xining", "liuzhou", "natal", "qinhuangdao", "hengyang", "taian", "teresina", "xinxiang", "sao bernardo do campo", "hegang", "campo grande", "athens", "cucuta", "langfang", "ningbo", "yantai", "zhuzhou", "jaboatao", "rajshahi", "sarajevo", "zhangjiakou", "cotonou", "zigong", "fuxin", "liaoyang", "sevilla", "la plata", "bangui", "osasco", "zhangdian", "puyang", "nantong", "mudanjiang", "santo andre", "hamilton", "joao pessoa", "shaoyang", "guilin", "frankfurt", "wahran", "mar del plata", "quebec", "zhanjiang", "zaragoza", "zhenjiang", "winnipeg", "dandong", "shaoguan", "yancheng", "foshan", "contagem", "jibuti", "haikou", "sao jose dos campos", "taizhou", "xingtai", "glasgow", "jinzhou", "abu dhabi", "luancheng", "dortmund", "stuttgart", "yingkou", "zhangzhou", "belfast" }; Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/office/add"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); // Input name String nameComp = faker.company().name(); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys(nameComp); // Input address String addressComp = faker.address().fullAddress(); driver.findElement(By.id("address")).clear(); driver.findElement(By.id("address")).sendKeys(addressComp); // Input city String cityComp = faker.address().city(); driver.findElement(By.id("city")).clear(); driver.findElement(By.id("city")).sendKeys(cityComp); // Input postal code String postalCodeComp = faker.address().zipCode(); driver.findElement(By.id("postalCode")).clear(); driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp); // Country// w ww.j a v a2 s .c o m Select countryComp = new Select(driver.findElement(By.id("country"))); int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1; countryComp.selectByIndex(coutryCompInt); // Email String emailComp = faker.internet().emailAddress(); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys(emailComp); // Phone String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("phone")).clear(); driver.findElement(By.id("phone")).sendKeys(phoneComp); // Mobile String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", ""); driver.findElement(By.id("mobilePhone")).clear(); driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp); // Fax String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("fax")).clear(); driver.findElement(By.id("fax")).sendKeys(faxComp); // Geolocation int cityN = r.nextInt(city.length); driver.findElement(By .xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/input")) .sendKeys(city[cityN]); driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/a")) .click(); Thread.sleep(3000); // SAVE driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[12]/div/button")) .click(); }
From source file:administrationedit.setSeasonTemplate.java
public static void main(String[] args) throws InterruptedException { for (int y = 0; y < 2; y++) { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/accommodation/seasonTemplateAdd"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); int currentYear = Calendar.getInstance().get(Calendar.YEAR) + y; String curYear = String.valueOf(currentYear); // Input name of template driver.findElement(By.id("name")).sendKeys("Season-" + curYear); // Choose year Select year = new Select(driver.findElement(By.id("year"))); year.selectByVisibleText(curYear); // Now select seasons WebElement tableId = driver.findElement(By.xpath("//*[@class='ui-calendar hasDatepicker']")); if (year.getFirstSelectedOption().getText().equals(curYear)) { String id = tableId.getAttribute("id"); for (int i = 1; i <= 12; i++) { Thread.sleep(1000); for (int j = 1; j <= 7; j++) { if (!driver.findElements(By.xpath( "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a")) .isEmpty()) { driver.findElement(By.xpath( "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a")) .click(); break; }/*from w w w .ja va 2 s .c om*/ } i++; int weeks = driver .findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr")) .size(); int test = 0; for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) { test = 1; break; } else test = 2; } switch (test) { case 1: for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) { driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); Select season1 = new Select(driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); int season1int = r.nextInt(season1.getOptions().size() - 1) + 1; season1.selectByIndex(season1int); driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]")) .click(); break; } } break; case 2: for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).isEmpty()) { driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); Select season2 = new Select(driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); int season2int = r.nextInt(season2.getOptions().size() - 1) + 1; season2.selectByIndex(season2int); driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]")) .click(); break; } } } } } // SAVE wait.until(ExpectedConditions.visibilityOfElementLocated( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input"))); driver.findElement(By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input")) .click(); if (driver.getTitle().equals("Accommodation season templates administration")) { driver.close(); } } }
From source file:adminPanel.scenarios.GeneratorInstances.java
private void setPhoto() { WebElement fileInput = webDriver.findElement(By.xpath("//*[@id=\"file_ajax\"]")); fileInput.sendKeys("/Users/oleg/IdeaProjects/NGC_Tests/src/test/resources/images/doctor_avatar.png"); }
From source file:adminPanel.scenarios.GeneratorInstances.java
private void setPhoto(String path) { WebElement fileInput = webDriver.findElement(By.xpath("//*[@id=\"file_ajax\"]")); fileInput.sendKeys("/Users/oleg/IdeaProjects/NGC_Tests/src/test/resources/images/" + path); }