1

My webdrive code which is written in JAVA given below works fine on FF but the same code gives error while running using IE11. Can you please help to find out why this is happening? My IE open up and it also loads the website (I did turn on protected mode of IE11 to run it smoothly) but after that it doesn't recognize the element. You can comment line of IE driver and uncomment line of FF driver and the code will execute without any issue.

My code:

WebDriver myD = null; File file = new File("C:/Users/pritik/Desktop/WebDriver/Drivers/IEDriverServer_x64_2.43.0/IEDriverServer.exe"); System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); myD = new InternetExplorerDriver(); // myD= new FirefoxDriver(); myD.navigate().to("http://lp2domapptst.lpdomain.com:10000/ucl/login/jsp/universal_login.jsp"); String a; a= KW.waitTime("3000"); WebElement we = myD.findElement(By.xpath("//input[@name='j_username']")); we.sendKeys("test"); we = myD.findElement(By.xpath("//input[@name='j_password']")); we.sendKeys("test"); myD.findElement(By.xpath("//button[@name='btnEnter']")).click(); 

I get the following Exception:

org.openqa.selenium.InvalidSelectorException: The xpath expression '//input[@name='j_username']' cannot be evaluated or does notresult in a WebElement (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 94 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:58' System info: host: 'cod8PKOTHAVALE', ip: '10.30.75.6', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_40' Session ID: d56eacc2-4739-4017-bb00-c06b01930d91 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:25808/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) 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.findElementByXPath(RemoteWebDriver.java:449) at org.openqa.selenium.By$ByXPath.findElement(By.java:357) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344) at testOrder.myTest(testOrder.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

2 Answers 2

1

Try this:

myD.navigate().to("http://lp2domapptst.lpdomain.com:10000/ucl/login/jsp/universal_login.jsp"); String a; a= KW.waitTime("3000"); WebElement we = myD.findElement(By.name("j_username")); Int timeoutInSeconds = 10; WebDriverWait wait = new WebDriverWait(mD, timeoutInSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("j_username")); we.sendKeys("test"); 

I can only assume that IE cannot see the element yet as the DOM may have been manipulated.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok I will try this too and will let you know.
Hi TidusJar I tried this but this code is also not working :(.
I get the same exception I described in the question above.
0

Find the input by name instead:

WebElement we = myD.findElement(By.name("j_username")); 

5 Comments

Hi Alecxe, Thanks for the reply. I did try it but it doesn't work using IE11 again. It works using FF though. I specifically want to use IE because that site supports only IE. Exception---> org.openqa.selenium.NoSuchElementException: Unable to find element with name == j_username (WARNING: The server did not provide any stacktrace information)
@ForTesting okay, but what error are you getting now?
I get this Exception -- org.openqa.selenium.NoSuchElementException: Unable to find element with name == j_username (WARNING: The server did not provide any
I wonder why it has issue only on IE. FF and Chrome both are fine.
@ForTesting I think the TidusJar's answer should solve it - by.name used with an explicit wait. Check it out.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.