List of usage examples for org.openqa.selenium By xpath
public static By xpath(String xpathExpression)
From source file:AUSA.vehicleCompScreen.java
public static void ocupantesSection() throws Exception { int ocuPant = ranYearNumbr(1, 4); for (int ocu = 1; ocu <= ocuPant; ocu++) { driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_BtnAddOccupants")).click(); Thread.sleep(500);//from w w w . j a v a2s .c o m } String ocuPants = driver.findElement(By.xpath("//*[contains(@id,'ctl00_ContentZone_ctrlVehicle_Vehicle')]")) .getAttribute("id"); int ocuPantNumber = Integer.parseInt(ocuPants.substring(37, 39)); int totalOcupant = ocuPantNumber + ocuPant; if (ocuPant == 1) { int nameGender = ranYearNumbr(0, personsT.length - 1); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + nameLast)) .sendKeys(personsT[nameGender]); selectDropDownClick2("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + located); new Select(driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + gender))) .selectByIndex(genderT[nameGender]); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + age)) .sendKeys(ranYearNumbr(30, 45) + ""); selectDropDownClick2("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + status); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + home)) .sendKeys("ESPAA"); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + DNI)) .sendKeys(dniLetra(ranYearNumbr(10000000, 40000000))); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + phone)) .sendKeys(ranYearNumbr(900000000, 980000000) + ""); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocuPantNumber + description)) .sendKeys("QA TESTER TECSIDEL"); Thread.sleep(2500); } else { for (int ocup = ocuPantNumber; ocup < totalOcupant; ocup++) { int nameGender = ranYearNumbr(0, personsT.length - 1); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + nameLast)) .sendKeys(personsT[nameGender]); selectDropDownClick2("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + located); new Select(driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + gender))) .selectByIndex(genderT[nameGender]); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + age)) .sendKeys(ranYearNumbr(30, 45) + ""); selectDropDownClick2("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + status); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + home)).sendKeys("ESPAA"); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + DNI)) .sendKeys(dniLetra(ranYearNumbr(10000000, 40000000))); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + phone)) .sendKeys(ranYearNumbr(900000000, 980000000) + ""); driver.findElement(By.id("ctl00_ContentZone_ctrlVehicle_Vehicle" + ocup + description)) .sendKeys("QA TESTER TECSIDEL"); Thread.sleep(2500); } } Thread.sleep(1000); driver.findElement(By.id("ctl00_ButtonsZone_BtnSave_IB_Label")).click(); Thread.sleep(1000); driver.findElement(By.id("ctl00_ContentZone_BtnPnlConfirm")).click(); Thread.sleep(3000); }
From source file:automated_tests.InitialPopups.java
@Test(priority = 6) public void quiz() { //Click Patient History form driver.findElement(By.xpath(".//*[@id='btn_PH']/div/a")).click(); //Wait until the Patient History form appears wait.until(ExpectedConditions.visibilityOfElementLocated( By.xpath("//*[@id='patient_feedback']/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/label/span"))); System.out.println("opened Patient History"); try {/* www . j a va 2 s. c o m*/ assertEquals("Female", driver.findElement( By.xpath("//form[@id='patient_feedback']/div/div/div[2]/div[2]/div/div[2]/label")) .getText()); } catch (Error e) { verificationErrors.append(e.toString()); System.out.println("Verification Errors:" + verificationErrors.toString()); } //Click Female button driver.findElement(By.xpath("//form[@id='patient_feedback']/div/div/div[2]/div[2]/div/div[2]/label")) .click(); }
From source file:backend.MakeUserTest.java
@Test(description = "open user panel", priority = 1) public void openUserPage() { driver.findElement(By.partialLinkText("Admin")).click(); driver.findElement(By.partialLinkText("Users")).click(); WebDriverWait wait = new WebDriverWait(driver, 10); WebElement elementButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//span[@onclick=\"dialog.formDialog(null,'person', { refresh : 'detailTable_person'}, {})\"]"))); }
From source file:backend.MakeUserTest.java
@Test(description = "create user", priority = 2, dependsOnMethods = { "openUserPage" }) public void makeUser() { WebDriverWait wait = new WebDriverWait(driver, 10); driver.findElement(By.xpath( "//span[@onclick=\"dialog.formDialog(null,'person', { refresh : 'detailTable_person'}, {})\"]")) .click();//from w w w . j a v a 2 s. c o m WebElement elementUsername = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username"))); textInput("username", "testUser123"); textInput("userRealName", "test user"); textInput("givenName", "test"); textInput("familyName", "user"); textInput("email", "testuser@gmail.com"); driver.findElement(By.partialLinkText("Password")).click(); WebElement elementPassword = wait .until(ExpectedConditions.visibilityOfElementLocated(By.id("newPassword"))); textInput("newPassword", "test123"); textInput("newPassword2", "test123"); driver.findElement(By.xpath("//span[text()='OK']")).click(); WebElement elementButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//span[@onclick=\"dialog.formDialog(null,'person', { refresh : 'detailTable_person'}, {})\"]"))); }
From source file:backend.MakeUserTest.java
@Test(description = "check if new user was succesfully added", priority = 3, dependsOnMethods = { "makeUser" }) public void validateNewUser() throws InterruptedException { WebDriverWait wait = new WebDriverWait(driver, 10); //sort descending(newest on top) WebElement table = driver.findElement(By.id("detailTable_person")); WebElement idCell = table.findElement(By.xpath("//th[text()='Id']")); idCell.click();//from www . j a va2s . c o m Thread.sleep(500); //select first table entry List<WebElement> tableRows = table.findElements(By.tagName("tr")); String userId = tableRows.get(2).findElement(By.xpath("//td[1]")).getText(); String nameCell = tableRows.get(2).findElement(By.xpath("//td[2]")).getText(); //validate if first entry is the new user. delete user if true, fails test if false if (nameCell.equals("testUser123")) { WebElement delete = table.findElement(By.xpath("//span[@onclick=\"dialog.deleteDialog('" + userId + "','person',{ refresh : 'null'}, null)\"]")); delete.click(); WebElement elementConfirm = wait .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Delete']"))); WebElement confirm = table.findElement(By.xpath("//span[text()='Delete']")); confirm.click(); WebElement elementButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//span[@onclick=\"dialog.formDialog(null,'person', { refresh : 'detailTable_person'}, {})\"]"))); } else { org.testng.Assert.fail("Test user was not succesfully created."); } }
From source file:barChart1.BarChartDemo.java
License:Open Source License
/** * Starting point for the demonstration application. * * @param args ignored./*from w ww . j a va2s . c o m*/ */ public static void main(String[] args) { // Demo to buy tickets to the EK 2016 System.out.println("Hello UEFA 2016 !!!"); statistics = ""; JOptionPane.showMessageDialog(null, "Belgium versus Italy demo start"); driver = new FirefoxDriver(); wait = new WebDriverWait(driver, 500); //Open Home Page driver.manage().window().maximize(); driver.get("http://www.uefa.com/"); wait.until(ExpectedConditions.visibilityOfElementLocated( By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']"))); driver.findElement(By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']")).click(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Teams']"))); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Matches']"))) .click(); wait.until(ExpectedConditions.visibilityOfElementLocated( By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']"))); driver.findElement( By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']")) .click(); wait2Secs(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div//ul/li/span[text()='Belgium']"))); driver.findElement(By.xpath("//div/div/div//ul/li/span[text()='Belgium']")).click(); // Belgium wait2Secs(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]"))); driver.findElement(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]")).click(); wait2Secs(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Pre-match']"))); // Go to the statistics driver.get("http://www.uefa.com/uefaeuro/season=2016/statistics/index.html"); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Teams']"))); driver.findElement(By.xpath("//a/span[text()='Teams']")).click(); // Look up the statistics for Belgium and Italy getOverviewStats("BE", "ITA", "Belgium", "Italy"); wait.until( ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium"); ; wait2Secs(); // getGoalsStats("BE","ITA","Belgium","Italy"); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium"); ; wait2Secs(); wait.until( ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click(); wait2Secs(); // Italy wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy"); ; wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Overview']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Overview']")).click(); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy"); ; wait.until( ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click(); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy"); ; wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click(); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy"); ; wait.until( ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy"); ; driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); JOptionPane.showMessageDialog(null, "Belgium versus Italy : \n" + statistics); BarChartDemo demo = new BarChartDemo("Belgium vs Italy"); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); }
From source file:barChart1.BarChartDemo.java
License:Open Source License
public static String getOverviewStats(String country, String secondcountry, String countryName, String secondCountryName) { wait.until(ExpectedConditions/*from ww w .ja va2 s . c o m*/ .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Overview']"))); driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Overview']")).click(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys(countryName); ; wait2Secs(); String matchesPlayed1 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[2]")).getText(); String wins1 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[3]")).getText(); String draws1 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[4]")).getText(); String losses1 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[5]")).getText(); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).clear(); wait2Secs(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")) .sendKeys(secondCountryName); ; wait2Secs(); // Italy String matchesPlayed2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[2]")).getText(); String wins2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[3]")).getText(); String draws2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[4]")).getText(); String losses2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[5]")).getText(); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).clear(); wait2Secs(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")) .sendKeys(secondCountryName); ; wait2Secs(); // Italy String matchesPlayed2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[2]")).getText(); String wins2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[3]")).getText(); String draws2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[4]")).getText(); String losses2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[5]")).getText(); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).clear(); wait2Secs(); wait.until(ExpectedConditions .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']"))); driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")) .sendKeys(secondCountryName); ; wait2Secs(); // Italy String matchesPlayed2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[2]")).getText(); String wins2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[3]")).getText(); String draws2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[4]")).getText(); String losses2 = driver.findElement(By.xpath("//tbody/tr[@class='off odd']/td[5]")).getText(); return statistics; }
From source file:barChart1.BarChartDemo.java
License:Open Source License
public static String getGoalsStats(String country) { String totalGoalsBE = driver.findElement(By.xpath("//tbody/tr[@class='on odd']/td[2]")).getText(); statistics = statistics + "Total goals " + country + ": " + totalGoalsBE + "\n"; String totalCounterBE = driver.findElement(By.xpath("//tbody/tr[@class='on odd']/td[4]")).getText(); statistics = statistics + "Total goals " + country + ": " + totalCounterBE + "\n"; return statistics; }
From source file:basicweb.WorkingWithElementsList.java
@Test public void testListOfElements() throws Exception { boolean isChecked = false; List<WebElement> radioButtons = driver .findElements(By.xpath("//input[contains(@type,'radio') and contains(@name,'cars')]")); int size = radioButtons.size(); System.out.println("Size of the list: " + size); for (int i = 0; i < size; i++) { isChecked = radioButtons.get(i).isSelected(); if (!isChecked) { radioButtons.get(i).click(); Thread.sleep(2000);//w w w .j a va 2s . c o m } } }
From source file:be.rubus.web.testing.CommonElementCode.java
License:Apache License
protected WebElement getParent(WebElement element) { return element.findElement(By.xpath("..")); }