Selenium:WebElement即使可见也未找到

时间:2018-09-08 15:46:43

标签: selenium-webdriver

TestNG - Version 6.14
Windows - 10
Selenium - 3.13

请在eclipse中运行以下代码以查看硒是否抛出org.openqa.selenium.NoSuchElementException:无法找到元素:// input [@ id ='inputEmail']

package onlinePractice;

import java.util.ArrayList;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class testCasesphpTravelsTest {

    String baseUrl = "http://phptravels.com/demo/";
    String driverPath = "C:/Marionette/geckodriver.exe";
    WebDriver driver;

    @Test
  public void login() {
  System.setProperty("webdriver.gecko.driver", driverPath);
  driver = new FirefoxDriver();
  driver.get(baseUrl);

  WebElement login = driver.findElement(By.linkText("LOGIN"));

  if (login.isDisplayed()) 
  login.click();

  WebElement email = driver.findElement(By.xpath("//input[@id='inputEmail']"));


    }
}

0 个答案:

没有答案