Example #1
0
 public void mouseHoverByXpath(String locator) {
   try {
     WebElement element = driver.findElement(By.xpath(locator));
     Actions action = new Actions(driver);
     Actions hover = action.moveToElement(element);
   } catch (Exception ex) {
     System.out.println("First attempt has been done, This is second try");
     WebElement element = driver.findElement(By.cssSelector(locator));
     Actions action = new Actions(driver);
     action.moveToElement(element).perform();
   }
 }
 @Test
 public void testUntitled2() throws Exception {
   driver.get(baseUrl + "php4dvd/");
   WebElement userNameWebEdit = driver.findElement(By.id("username"));
   WebElement passwordWebEdit = driver.findElement(By.name("password"));
   WebElement subminButton = driver.findElement(By.name("submit"));
   userNameWebEdit.clear();
   userNameWebEdit.sendKeys("admin");
   passwordWebEdit.clear();
   passwordWebEdit.sendKeys("admin");
   subminButton.click();
 }
Example #3
0
 @Test
 public void testCreateFilm() throws Exception {
   driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
   driver.findElement(By.name("name")).clear();
   driver.findElement(By.name("name")).sendKeys("Новый фильм");
   driver.findElement(By.name("year")).clear();
   driver.findElement(By.name("year")).sendKeys("1999");
   driver.findElement(By.name("duration")).clear();
   driver.findElement(By.name("duration")).sendKeys("90");
   driver.findElement(By.id("own_no")).click();
   driver.findElement(By.id("seen_no")).click();
   driver.findElement(By.id("submit")).click();
 }
Example #4
0
 // Keys
 public void clearInputBox(String locator) {
   driver.findElement(By.cssSelector(locator)).clear();
 }
Example #5
0
 // get WebElements
 public List<WebElement> getWebElements(String locator) {
   List<WebElement> elements = driver.findElements(By.cssSelector(locator));
   return elements;
 }
Example #6
0
  public WebElement getWebElementByXpath(String locator) {
    WebElement element = driver.findElement(By.xpath(locator));

    return element;
  }
Example #7
0
  public List<WebElement> getWebElementsByCss(String locator) {
    List<WebElement> elementList = new ArrayList<WebElement>();
    elementList = driver.findElements(By.cssSelector(locator));

    return elementList;
  }
Example #8
0
  public WebElement getWebElementByCss(String locator) {
    WebElement element = driver.findElement(By.cssSelector(locator));

    return element;
  }
Example #9
0
  public String getTextByXpath(String locator) {
    String st = driver.findElement(By.xpath(locator)).getText();

    return st;
  }
Example #10
0
  public String getTextByCss(String locator) {
    String st = driver.findElement(By.cssSelector(locator)).getText();

    return st;
  }
Example #11
0
 public void clickByName(String locator) {
   driver.findElement(By.id(locator)).click();
 }
Example #12
0
 public void typeByXpath(String locator) {
   driver.findElement(By.xpath(locator)).click();
 }
Example #13
0
 public void typeByCssThenEnter(String locator, String value) {
   driver.findElement(By.cssSelector(locator)).sendKeys(Keys.CLEAR, value, Keys.ENTER);
 }
Example #14
0
 public void typeByCss(String locator, String value) {
   driver.findElement(By.cssSelector(locator)).sendKeys(value, Keys.CLEAR);
 }
Example #15
0
 public void clickByCss(String locator) {
   driver.findElement(By.cssSelector(locator)).click();
 }
Example #16
0
 // get Links
 public void getLinks(String locator) {
   driver.findElement(By.linkText(locator)).findElement(By.tagName("a")).getText();
 }
Example #17
0
  @Test
  public void testVip7day() throws Exception {

    driver
        .manage()
        .timeouts()
        .implicitlyWait(30, TimeUnit.SECONDS); // неявное ожидание при каждом поиске элементов
    driver.get("http://mylove.ru");

    driver.findElement(By.id("mprofile_link")).click();
    driver.findElement(By.cssSelector("#isvip")).click();

    if (isElementPresent(By.xpath("//*[@id='settings']"))) {
      driver.findElement(By.xpath("//*[@id='settings']//a[contains(@class,'techbutton')]")).click();
    }
    Pattern pat = Pattern.compile("[-]?[0-9]+(.[0-9]+)?");
    // String Str1= driver.findElement(By.cssSelector("div.vipend > i")).getText();
    String Str1 =
        driver
            .findElement(
                By.cssSelector("#body > div.window.pay_window > div > div.paymay > div.vipend > i"))
            .getText();

    Matcher matcher1 = pat.matcher(Str1);
    while (matcher1.find()) Str1 = matcher1.group(); // что-то происходит

    Str1 = Str1.replaceAll(" ", "");
    Integer i1 = Integer.valueOf(Str1);
    // driver.findElement(By.xpath("//*[@id=\"vip_settings\"]/div[2]/a[1]")).click(); тоже верно

    driver.findElement(By.cssSelector("#vip_settings  div.pcols > a")).click();

    Thread.sleep(
        1000); /// без ожидания не успевает измениться выбранное значение дней, потом заменить на
               // явное ожидание с условием
    driver
        .findElement(By.cssSelector("div.pay_variant.pay_bill.pay_variant_cash > a"))
        .click(); // Платим со счета

    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(
        ExpectedConditions.stalenessOf(
            driver.findElement(
                By.cssSelector(
                    "#isvip")))); // подождем когда какой то DOM исчезнет(( чтобы посмотреть сколько
                                  // теперь дней до окончания випа, долго работает

    driver.findElement(By.cssSelector("#isvip")).click();
    driver.findElement(By.xpath("//*[@id='settings']//a[contains(@class,'techbutton')]")).click();
    String Str2 = driver.findElement(By.cssSelector("div.vipend > i")).getText();

    Matcher matcher2 = pat.matcher(Str2);

    while (matcher2.find()) Str2 = matcher2.group();
    Str2 = Str2.replaceAll(" ", ""); // если дней больше 1000 то строка с пробелами
    Integer i2 = Integer.valueOf(Str2);
    i1 = i1 + 7;

    // Проверим что количество дней випа увеличилось на 7
    assertEquals(i2, i1);
  };
Example #18
0
  public String getTextByName(String locator) {
    String st = driver.findElement(By.name(locator)).getText();

    return st;
  }