NoSuchElementException:无法在Selenium webdriver中找到元素

时间:2016-06-23 15:26:30

标签: java selenium selenium-webdriver

我尝试使用linktext和href找到一个元素,但两者都不适用于我。奇怪的是,我能够在测试环境中找到元素并对同一元素执行操作,但在开发环境中失败。我没有看到测试和开发环境规格有任何区别。

代码

WebDriver driver=new FirefoxDriver();
driver.get("http://*****.com");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated((By.linkText("Register/Create an Account"))));
driver.findElement(By.linkText("Register/Create an Account")).click(); or
driver.findElement(By.xpath("//a[@href='********']")).click();

错误

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Register/Create an Account"}
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
Session ID: 8757a2e4-a195-4ce0-b043-0f6c3decacc8
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=31.0}]
    at sun.reflect.GeneratedConstructorAccessor11.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:401)
    at org.openqa.selenium.By$ByLinkText.findElement(By.java:242)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:730)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:728)
    at org.openqa.selenium.support.ui.ExpectedConditions$3.apply(ExpectedConditions.java:106)
    at org.openqa.selenium.support.ui.ExpectedConditions$3.apply(ExpectedConditions.java:1)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)

0 个答案:

没有答案