当前位置: 动力学知识库 > 问答 > 编程问答 >

java - org.openqa.selenium.nosuchelementexception Occuring when the element do exist

问题描述:

I have a simple Extjs-5 application for which I am writing tests.

Application is working perfectly fine on my local server. I have a search field which I was able to locate and test via Selenium and JUnit but when I try to click a button which is in my app, I am getting following exception

 org.openqa.selenium.NoSuchElementException: no such element

(Session info: chrome=42.0.2311.90)

(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 31 milliseconds

For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:32:56'

System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75'

Session ID: b2d6caa7ef4ee5c396c65899baa2b8a5

Driver info: org.openqa.selenium.remote.RemoteWebDriver

Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\SUESSD~1\AppData\Local\Temp\scoped_dir6284_5598}, rotatable=false, locationContextEnabled=true, version=42.0.2311.90, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, 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:191)

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)

at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)

at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:404)

at org.openqa.selenium.By$ByXPath.findElement(By.java:344)

at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)

at com.appfoundation.automation.framework.BaseModel.find(BaseModel.java:28)

at com.appfoundation.automation.example.model.MyModel.findAddButton(MyModel.java:30)

at com.appfoundation.automation.example.MyBaseTest.testResetForm(MyBaseTest.java:32)

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:47)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

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.rules.TestWatcher$1.evaluate(TestWatcher.java:55)

at org.junit.rules.RunRules.evaluate(RunRules.java:20)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

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.run(ParentRunner.java:309)

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: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)

My test class is:

public class MyBaseTest extends BaseSeleniumTest {

private MyModel model;

public MyBaseTest() {

model = new MyModel(this);

}

@Test

public void testResetForm(){

driver.get("http://localhost:1841/");

this.waitToBeClickable(MyModel.SEARCH_XPATH);

WebElement searchInput = model.findSearchInput();

WebElement addButton = model.findAddButton();

searchInput.sendKeys("Yawar");

assertEquals("Yawar", searchInput.getAttribute("value"));

addButton.click(); // Test Breaking at this line with the above mentioned exception

}

}

And This is my model class:

public class MyModel extends BaseModel {

public static final String SEARCH_XPATH = XPathUtils.findInputByName("searchField");

public static final String ADD_XPATH = XPathUtils.findButtonByText("Add");

public MyModel(BaseSeleniumTest test) {

super(test);

}

public WebElement findSearchInput(){

return this.find(SEARCH_XPATH);

}

public WebElement findAddButton(){

System.out.println(ADD_XPATH);

return find(ADD_XPATH);

}

}

I have found similar questions on stack overflow like org.openqa.selenium.NoSuchElementException: no such element

but they don't have an accepted answer and they are suggesting to increase wait which I did but same exception occurs in either case.

Kindly help.

分享给朋友:
您可能感兴趣的文章:
随机阅读: