我无法选择日期选择器。出现错误消息

时间:2017-07-04 08:47:10

标签: selenium

这是我的代码。当我尝试执行脚本时,会显示错误消息。我正在尝试从excel中选择一个日期选择器,其中所有方法都已保存。我已准备好excel并从excel中获取所有方法并执行脚本,但每次显示错误消息时都无法选择日期选择器。

    package com.rmspl.multiplemethod;

    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.Select;
    import org.openqa.selenium.support.ui.WebDriverWait;

    public class MethodSet {

        static WebElement element;

        public void login (String username,String password,String nr,WebDriver fd) throws InterruptedException {



        fd.get("http://msrtc.indiagis.org");    
        fd.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);



        WebElement E1 = fd.findElement(By.xpath("//a[contains(.,'VMS')]"));
        E1.click();

        WebElement E2 = fd.findElement(By.name("j_username"));
        E2.sendKeys(username);

        WebElement E3= fd.findElement(By.name("j_password"));
        E3.sendKeys(password);

        WebElement E4 = fd.findElement(By.name("log"));
        E4.click();

        }

      public void clickLink(String xPath,String nr,String nr1,WebDriver fd){
            new WebDriverWait(fd,90).until(ExpectedConditions.invisibilityOfElementLocated(By.id("loading_bg")));
            WebDriverWait wait = new WebDriverWait(fd,90);
            element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xPath)));
            element = fd.findElement(By.xpath(xPath));
            element.click();
        }


       public void Select(String xPath,String val,String nr1,WebDriver fd){
            Select sel = new Select(fd.findElement(By.xpath(xPath)));
            sel.selectByValue(val);
        }

       public void Sendkey(String xPath, String val, String nr1,WebDriver fd){
           element = fd.findElement(By.xpath(xPath));
           element.sendKeys(val);
       }
     public void checkbox(String xPath, String nr, String nr1,WebDriver fd){
     WebDriverWait wait = new WebDriverWait(fd,20);
    element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xPath)));
      element = fd.findElement(By.xpath(xPath));
      if(!element.isSelected())
      element.click();
  }
    }


package com.rmspl.multiplemethod;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class TestDriver {
    static WebElement element;
    public static void main(String[] args) throws BiffException, IOException, 
    NoSuchMethodException, SecurityException, 
    IllegalAccessException,IllegalArgumentException, InvocationTargetException {

    MethodSet mt = new MethodSet();

    ChromeOptions options = new ChromeOptions(); 
    options.addArguments("--start-maximized"); 
    options.addArguments("--disable-web-security"); 
    options.addArguments("--no-proxy-server"); 
    Map<String, Object> prefs = new HashMap<String, Object>(); 
    prefs.put("credentials_enable_service", false); 
    prefs.put("profile.password_manager_enabled", false); 
    options.setExperimentalOption("prefs", prefs); 

    System.setProperty("webdriver.chrome.driver","C:\\Users\\Arijit 
    Mohanty\\Desktop\\chromedriver.exe");
    WebDriver fd = new ChromeDriver(options);

    FileInputStream fis = new FileInputStream("C:\\Users\\Arijit 
    Mohanty\\Desktop\\Bangla\\HybridDatasheet.xls");
    Workbook WB = Workbook.getWorkbook(fis);
    Sheet Sh = WB.getSheet("Sheet2");

    int rows = Sh.getRows();
    int cols = Sh.getColumns();

    for (int i = 1; i<rows; i++)
        {
        String methodname = Sh.getCell(0, i).getContents();
        String data1 = Sh.getCell(1, i).getContents();
        String data2 = Sh.getCell(2, i).getContents();
        String data3 = Sh.getCell(3, i).getContents();

        Method m1 =  mt.getClass().getMethod(methodname, 
        String.class,String.class,String.class, WebDriver.class);
        m1.invoke(mt,data1,data2,data3,fd);
        }
    }
}

0 个答案:

没有答案