формат даты рождения в селене, веб-драйвер в java-программе - PullRequest
0 голосов
/ 07 января 2019

В Calender элементы не перемещаются к предыдущей и следующей кнопке и посередине, как писать код в селене, веб-драйвер в Java-программе.

я попробовал этот код ниже пакет com.s3sales.demo;

/*import java.util.Calendar;
import java.util.List;
*/
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions; 

public class S3sales {

    public static void main(String[] args) throws InterruptedException {

        WebDriver driver = new FirefoxDriver();

        driver.get("http://sssamriddhisales.com/crm");

        driver.findElement(By.id("userName")).sendKeys("admin");

        Thread.sleep(3000);

        driver.findElement(By.id("password")).sendKeys("admin123");     

        Thread.sleep(3000); 

        driver.findElement(By.className("btn-success")).click();

        Thread.sleep(1000);

         WebElement element = driver.findElement(By.linkText("Employee"));

         Thread.sleep(1000);

            Actions action = new Actions(driver);

    action.moveToElement(element).moveToElement(driver.findElement(By.cssSelector("[data-id='empRegistration']"))).click().build().perform();

    Thread.sleep(3000);

        driver.findElement(By.id("newEmployee")).click();

        driver.findElement(By.id("empFirstName")).sendKeys("Rakesh");

        driver.findElement(By.id("empLastName")).sendKeys("Yadav");

        String dateTime ="1993-10-09";

        // button to open calendar
        driver.findElement(By.id("empDob")).click();

        WebElement nextLine=driver.findElement(By.xpath("//div[@class='next']"));

        nextLine.click();

        //button to move next in calendar
    /*
         Actions action1 = new Actions(driver);

           WebElement driver1 = driver.findElement(By.xpath("//a[th(@class,'pre')]"));

           driver1.click();*/
         /*  WebElement prevLine = driver.findElement(By.xpath("//div[th@class='prev']"));

           prevLine.click();
     */
    }   
}

enter image description here

Исключение в потоке "main" org.openqa.selenium.NoSuchElementException: Невозможно найти элемент: // div [@ class = 'next']

не найдено таких элементов, показывающих в консоли, где и не удается найти элемент, показывающий, пожалуйста, помогите мне ..

Ответы [ 2 ]

0 голосов
/ 08 января 2019
  1. вы пытаетесь нажать на следующую кнопку локатора панели выбора даты (//div[@class='next']) поскольку он не существует, и в некоторых случаях может не работать другой локатор //th[@class='next'] так как он имеет 4 совпадающих узла в DOM. Вы можете попытаться нажать на следующую кнопку, используя ожидаемое условие (явное ожидание), как показано ниже

    WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='datepicker-days']//th[@class='next']")));<br> driver.findElement(By.xpath("//div[@class='datepicker-days']//th[@class='next']")).click();

  2. вам не нужно автоматизировать всю панель выбора даты, как вы можете видеть после ввода значения в поле ввода даты, отображаемое на панели, поэтому поиск локатора элемента был немного утомительным, чтобы найти уникальное соответствие, вы можете найти его ниже.

    String dateTime ="1993-10-09";
    String[] output = dateTime.split("-");
    String year = output[0];
    String day = output[2];
    String[] day1 = day.split("");
    WebDriverWait wait = new WebDriverWait(driver, 5); 
    

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//section[@class='section newSec none']/div//input[@id='empDob']")));

    driver.findElement(By.xpath("//section[@class='section newSec none']/div//input[@id='empDob']")).clear();
    driver.findElement(By.xpath("//section[@class='section newSec none']/div//input[@id='empDob']")).sendKeys(dateTime);
    
    //Wait until date is clickable in datepicker panel
    
    String datexpath = "//th[contains(text(),' "+year+"')]/ancestor::table//td[text()='"+day1[1]+"']";
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath(datexpath)));
    driver.findElement(By.xpath(datexpath)).click();
    
  3. Если вы действительно хотите автоматизировать всю панель выбора даты, вы можете обратиться к этому учебнику для автоматизации выбора даты

надеюсь, что это решит вашу проблему, дайте мне знать, если это работает для вас или у вас есть сомнения !!!

0 голосов
/ 07 января 2019

следующий элемент присутствует в теге th, а не теге div, поэтому xpath должен быть:

//th[@class='next']
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...