我通过执行以下代码获得以下异常。该代码适用于FirefoxDriver,只有InternetExplorerDriver失败。 我还添加了HTML&现在是Java代码。
例外:
org.openqa.selenium.NoSuchElementException: Unable to find element with id == devices_Number (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 316 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'
System info: host: 'ICA4502', ip: '192.168.5.37', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_09'
Session ID: dac482ae-dba1-4d57-807c-de22e443f9b1
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=9, ie.usePerProcessProxy=false, ignoreProtectedModeSettings=false, cssSelectorsEnabled=true, requireWindowFocus=false, initialBrowserUrl=http://localhost:40748/, handlesAlerts=true, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
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.findElementById(RemoteWebDriver.java:393)
at org.openqa.selenium.By$ById.findElement(By.java:214)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at com.java.selenium.example.SeleniumTest.startTest(SeleniumTest.java:30)
at com.java.selenium.example.SeleniumTest.main(SeleniumTest.java:15)
以下是html文件Test.Html
<html>
<head>
<title>Multi select Drop Down List Box</title>
</head>
<body>
<p>What all devices do you listen to music on?</p>
<BR>
<INPUT id="devices_Number" name="devices_Number_n" maxLength="10" value="Devices Number" >
<INPUT id="devices_Name" name="devices_Name_n" maxLength="10" value="Devices Name" >
<INPUT id="devices_Made" name="devices_Made_n" maxLength="10" value="Devices Made By" >
<INPUT id="devices_Version" name="devices_Version_n" maxLength="10" value="Devices Version" >
</body>
</html>
以下是selenium java文件SeleniumTest .java
package com.java.selenium.example;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
/**
*
* @author
*
*/
public class SeleniumTest {
private static WebDriver driver = null;
private final static String URL= "D:\\Selenium\\Text.html";
private final static String IE_DRIVER = "D:\\Dev_Env\\Tester\\driver\\IEDriverServer_2.44\\IEDriverServer.exe";
/**
* main method
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
startTest();
}
/**
* startTest
*/
private static void startTest() {
try {
System.setProperty("webdriver.ie.driver", new File(IE_DRIVER).getAbsolutePath());
//driver = new InternetExplorerDriver();
driver = new FirefoxDriver();
Thread.sleep(2000);
driver.get(URL);
Thread.sleep(2000);
driver.findElement(By.id("devices_Number")).clear();
Thread.sleep(200);
driver.findElement(By.id("devices_Number")).sendKeys("123456");
} catch (Exception e ) {
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
尝试以下
WebDriverWait driverWait = new WebDriverWait(driver,30000);
driverWait.until(ExpectedConditions.presenceOfElementLocated(By.id("devices_Number")));