import org.openqa.selenium.By;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Google_ie {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver", "E:\\Testing\\IEDriverServer.exe");
InternetExplorerDriver fd = new InternetExplorerDriver();
fd.get("http://www.google.com");
fd.findElement(By.name("q")).sendKeys("selenium");
fd.findElement(By.name("btnG")).click();
}
}
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Unable to find element with name == q (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 360 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
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=11, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:13289/, 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: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.findElementByName(RemoteWebDriver.java:425)
at org.openqa.selenium.By$ByName.findElement(By.java:299)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at automation.Google_ie.main(Google_ie.java:13)
请建议!!!
我甚至已经花了一些时间来检查
的Thread.sleep
但仍然收到错误!!!
答案 0 :(得分:0)
似乎是IExplorer配置问题。您必须按照以下步骤操作:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
。对于64位Windows安装,密钥为HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
。请注意,FEATURE_BFCACHE子项可能存在也可能不存在,如果不存在,则应创建该子项。要点:在此项中,创建名为iexplore.exe的值为0的DWORD值。答案 1 :(得分:0)
始终尝试将保护模式保持为真,这有5个安全原因,并且此错误将得到解决。 所以从这个链接中读取它 http://www.abodeqa.com/2014/11/26/challenges-to-run-selenium-webdriver-scripts-in-ie-browser/