-2

I am unable to identify any of webelements in a page using Selenium webdriver. Used 2.48.0 selenium jar. I have tried xpath absolute, relative path, css selector, id, name. All throwing NoSuchElementException. I am stucked here. please help me. I am able to login to application easily After login selecting a menu items will direct to a page. On that page, Will not be able to identify any elements.

Please find text box i am trying to enter html source:

<input class="AnswerText" type="text" onblur="$('#ind6').attr('class','ALIP-Icon sprite-icon_indicator_off'); " onfocus="gotFocus(this);$('#ind6').attr('class','ALIP-Icon sprite-icon_indicator'); removeFocus('ind6'); " maxlength="15" size="15" value="" name="7:/XML/ApplicationSummary/ContractNumber">

Console ErrorError:

Started InternetExplorerDriver server (64-bit)
2.48.0.0
Listening on port 43801
org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == /html/body/div/div/div/form/div[1]/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/div[2]/span/table/tbody/tr[1]/td[1]/div/div/table/tbody/tr/td[3]/input (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 377 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'V-INFSY-NBA121', ip: '172.30.1.102', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=false, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=true, handlesAlerts=true, version=9, platform=WINDOWS, nativeEvents=false, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:43801/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 38d52e22-4575-49b3-aaf4-25a96a7d177a
*** Element info: {Using=xpath, value=/html/body/div/div/div/form/div[1]/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/div[2]/span/table/tbody/tr[1]/td[1]/div/div/table/tbody/tr/td[3]/input}
    at sun.reflect.GeneratedConstructorAccessor9.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:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:490)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)
    at com.onfs.test.CommonMethods.type(CommonMethods.java:558)
    at com.onfs.test.Application_Entry.testMethod(Application_Entry.java:83)
    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:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Guy
  • 46,488
  • 10
  • 44
  • 88
joseph
  • 1
  • 2
  • Can you add that HTML code ? – N.. Dec 31 '15 at 15:46
  • This is the code i tried to use driver.findElement(By.xpath("/html/body/div/div/div/form/div[1]/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/div[2]/span/table/tbody/tr[1]/td[1]/div/div/table/tbody/tr/td[3]/input")).sendKeys("1234567"); – joseph Dec 31 '15 at 15:49

2 Answers2

1

I think there is sync issue. I would wait for that element to appear before start sending value. Please use following code and try to run. It should work.

I replace xpath to by name or you can try with Class too. You have really big xpath. In my view it is not good to have that long.

    WebDriverWait wait = new WebDriverWait(driver, timeoutWait);
                wait.until(ExpectedConditions.visibilityOf(By.name("7:/XML/ApplicationSummary/ContractNumber"))).sendKeys("1234567")

Detail documentation of WebDriverWait

N..
  • 906
  • 7
  • 23
  • Thanks Boston for your reply. It dint work out. i have used below code WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("7:/XML/ApplicationSummary/ContractNumber"))).sendKeys("1234567"); it got error message. This is similar to noSuchElementException. Even I tried to set using javascript executescript method, still getting NoSuchElementException. none of elements in that page is not getting recognized. its weird. – joseph Dec 31 '15 at 16:50
  • I think you are using selenium server. Please try to run locally and see it is performing and than try to run this code. You can debug easily. You need to add more time if you want. upto 1 min. – N.. Dec 31 '15 at 16:52
  • org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for visibility of element located by By.name: 7:/XML/ApplicationSummary/ContractNumber Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12' System info: host: 'V-INFSY-NBA121', ip: '172.30.1.102', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65' – joseph Dec 31 '15 at 16:54
  • 10 Seconds is very less time some. If element is not presenting it means it can be behind iframe : http://stackoverflow.com/questions/24247490/find-elements-inside-forms-and-iframe-java-selenium-webdriver – N.. Dec 31 '15 at 16:56
  • selenium server? you mean selenium server standalone 2.48.jar causing this issue? What is the alternative jar to be used instead of selenium server for Java – joseph Dec 31 '15 at 16:56
  • I gave 100 seconds too. It dint work out. Do we need to replace selenium server?? – joseph Dec 31 '15 at 16:58
  • Are you sure there is no Iframe ? before start look into selenium server – N.. Dec 31 '15 at 16:59
  • there are many iframe codes in htlml source. Would iframe cause NoSuchElementException. What is the fix if we have iframe – joseph Dec 31 '15 at 17:31
  • Do you need html source to look more about iframe? – joseph Dec 31 '15 at 17:35
  • It worked. boston. Thank you so much. you are really great. It worked. There was an iframe in that page...I have added below code driver.switchTo().frame(driver.findElement(By.id("containerIframe"))); and normal selenium code. it worked – joseph Dec 31 '15 at 17:40
0

Can you try the same with by disabling protective mode? lets do below way and may i know what is issue if still you are facing and also provide code

  1. go for IEDriverServer.exe 32 bit and use the same
  2. un-check all the zones in security tab
  3. try with short xpath specified in another answer if yours does not works
  4. try without waits first, wait, if it fails then thread.sleep

thanks

murali selenium
  • 3,847
  • 2
  • 11
  • 20