想在selenium web驱动程序中为多个命令编写一个代码

时间:2015-12-24 07:15:46

标签: selenium selenium-webdriver

WebElement element1 = driver.get("http://staging.zingoy.com/");
      WebElement element11 = driver.get("http://staging.zingoy.com/login");

    if (element1!= null && element11!= null ){
    driver.findElement(By.xpath("/html/body/div[1]/nav/div/div/div[4]/div/span[2]/a[1]")).click();
    System.out.println("LOGin Enter text");
    try{
          WebDriverWait wait = new WebDriverWait(driver, 10);
          WebElement element = (WebElement) wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[1]/div[1]/div/div/div[2]/div/div[3]/div/form/div[2]/input")));
          element.click();
          System.out.println("Clicked on the element successfully");
        }catch(Throwable e){
          System.err.println("Error came while waiting for the element and clicking on it. "+e.getMessage());
        }

    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/div/div[2]/div/div[3]/div/form/div[2]/input")).sendKeys("mdimertest@gmail.com");
    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/div/div[2]/div/div[3]/div/form/div[3]/input")).sendKeys("12345600");
    driver.findElement(By.id("login_submit")).click();

2 个答案:

答案 0 :(得分:2)

driver.get()返回void,您无法将其分配给WebElement(前两行)。

答案 1 :(得分:2)

driver.get(" URL")打开指定网址中的网页,该网页为空。 它无法分配给WebElement。 尝试将浏览器中打开的页面中的任何元素分配给element1,并将其检查为null。