List of usage examples for org.openqa.selenium By id
public static By id(String id)
From source file:TestWithSelenium.java
@Test public void xTestEdit() { //searching for tbody List<WebElement> tableRows = (new WebDriverWait(driver, MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); WebElement editButton = null;// ww w .j av a 2 s . c o m for (int i = 0; i < tableRows.size(); i++) { if (tableRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { editButton = tableRows.get(i); break; } } editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0).click(); WebElement element = driver.findElement(By.id("description")); element.clear(); element.sendKeys("Cool car"); driver.findElement(By.id("save")).click(); //searching for new tbody List<WebElement> tableRowsUpdated = (new WebDriverWait(driver, MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); String descriptionNew = ""; for (int i = 0; i < tableRowsUpdated.size(); i++) { if (tableRowsUpdated.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { descriptionNew = tableRowsUpdated.get(i).findElements(By.tagName("td")).get(5).getText(); break; } } assertThat(descriptionNew, is("Cool car")); }
From source file:TestWithSelenium.java
@Test public void yTestError() { driver.findElement(By.id("new")).click(); driver.findElement(By.id("save")).click(); String submiterrMessage = (new WebDriverWait(driver, MAX)) .until((ExpectedCondition<String>) (WebDriver d) -> { return d.findElement(By.id("submiterr")).getText(); });//from w w w . j a v a2 s . c o m assertThat(submiterrMessage, is("All fields are required")); }
From source file:TestWithSelenium.java
@Test public void zAddNew() { driver.findElement(By.id("new")).click(); driver.findElement(By.id("year")).sendKeys("2008"); driver.findElement(By.id("registered")).sendKeys("2002-5-5"); driver.findElement(By.id("make")).sendKeys("Kia"); driver.findElement(By.id("model")).sendKeys("Rio"); driver.findElement(By.id("description")).sendKeys("As new"); driver.findElement(By.id("price")).sendKeys("31000"); driver.findElement(By.id("save")).click(); WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); });//from w w w . j a v a2s .c o m Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(6)); }
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//from w ww . j ava 2 s . c o 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:$.BaseSeleniumTestCase.java
License:Apache License
/** * ?, .//from w w w . j a v a 2 s . c om */ protected static void loginAsUserIfNecessary() { s.open("/task"); if (s.getTitle().contains("")) { s.type(By.name("username"), "user"); s.type(By.name("password"), "user"); s.check(By.name("rememberMe")); s.click(By.id("submit_btn")); s.waitForTitleContains("?"); } }
From source file:$.ProfileFT.java
License:Apache License
/** * .//from ww w . j a va2s. c o m */ @Test public void editProfile() { s.open("/profile"); s.type(By.id("name"), "Kevin"); s.click(By.id("submit_btn")); assertThat(s.isTextPresent("Kevin")).as("??").isTrue(); }
From source file:$.RegisterFT.java
License:Apache License
@Test public void register() { // //from w w w . j a v a 2s . c o m s.open("/logout"); s.click(By.linkText("")); s.type(By.id("loginName"), "user2"); s.type(By.id("name"), "Kevin"); s.type(By.id("plainPassword"), "user2"); s.type(By.id("confirmPassword"), "user2"); s.click(By.id("submit_btn")); // s.waitForTitleContains(""); assertThat(s.getValue(By.name("username"))).isEqualTo("user2"); s.type(By.name("password"), "user2"); s.click(By.id("submit_btn")); // ? s.waitForTitleContains("?"); // s.open("/logout"); }
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 ww .j a v a2 s .c o m*/
From source file:$.SecurityFT.java
License:Apache License
/** * ???./* w w w . j av a 2s .co m*/ */ @Test public void loginWithWrongPassword() { s.open("/logout"); s.type(By.name("username"), "wrongUser"); s.type(By.name("password"), "WrongPassword"); s.check(By.name("rememberMe")); s.click(By.id("submit_btn")); s.waitForTitleContains(""); assertThat(s.isTextPresent("?.")).isTrue(); }
From source file:$.SimpleTest.java
License:Apache License
@Test public void testSimple() throws Exception { this.driver.get(this.serverUrl + "index.html"); String whoToSend = "foo"; WebElement who = this.driver.findElement(By.id("who")); who.sendKeys(whoToSend);/*from ww w . jav a 2 s . com*/ WebElement sendBtn = this.driver.findElement(By.id("send-btn")); sendBtn.click(); // wait 5 secs for ajax response new WebDriverWait(this.driver, 5) .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend)); WebElement response = this.driver.findElement(By.id("response")); String text = response.getText(); Assert.assertEquals("Hello " + whoToSend, text); }