First Test Case with Selenium error

First Test Case with Selenium
http://www.toolsqa.com/selenium-webdriver/first-test-case/

error:

Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”.//*[@id=’account_logout’]/a”}
Command duration or timeout: 10.02 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.43.0’, revision: ‘597b76b’, time: ‘2014-09-09 20:52:38’
System info: host: ‘Selenium’, ip: ‘192.168.117.64’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_67′
Session ID: af9469d3-1db5-4b32-a2a6-9b722c587532
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=32.0.1}]
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 automationFramework.FirstTestCase.main(FirstTestCase.java:53)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”.//*[@id=’account_logout’]/a”}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.43.0’, revision: ‘597b76b’, time: ‘2014-09-09 20:52:38’
System info: host: ‘Selenium’, ip: ‘192.168.117.64’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_67’
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/pc/AppData/Local/Temp/anonymous1450587665133173591webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9618:133)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/pc/AppData/Local/Temp/anonymous1450587665133173591webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:548:5)

Default Asked on September 16, 2014 in Selenium WebDriver.
Add Comment
  • 7 Answer(s)

    Hi,

    Have you registered at the mentioned site?

    Thanks,
    Vishal S

    Doctor Answered on September 16, 2014.

    Can you try to add the following line after the login click.

    Thread.sleep(time in ms);

    on September 16, 2014.
    Add Comment

    HI,,, instead of .//*[@id=’account_logout’]/a” xpath, use this:  //div[@id=’account_logout’]

    Default Answered on September 16, 2014.
    Add Comment

    Error appears (full string:  driver.findElement (By.xpath(“//div[@id=’account_logout’]”)).click();  ):

    Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”//div[@id=’account_logout’]”}
    Command duration or timeout: 10.09 seconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: ‘2.43.0’, revision: ‘597b76b’, time: ‘2014-09-09 20:52:38’
    System info: host: ‘Selenium’, ip: ‘192.168.117.64’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_67′
    Session ID: 1199ff54-3077-48ea-b161-2fccdb9ea372
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{platform=WINDOWS, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=32.0.1}]
    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 automationFramework.FirstTestCase.main(FirstTestCase.java:53)
    Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”//div[@id=’account_logout’]”}
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: ‘2.43.0’, revision: ‘597b76b’, time: ‘2014-09-09 20:52:38’
    System info: host: ‘Selenium’, ip: ‘192.168.117.64’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_67’
    Driver info: driver.version: unknown
    at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/pc/AppData/Local/Temp/anonymous44213260412626336webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9618:133)
    at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/pc/AppData/Local/Temp/anonymous44213260412626336webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:548:5)

    Default Answered on September 16, 2014.
    Add Comment

    You can try this

    Thread.sleep(1000);
    drive.findElement(By.xpath(“/html/body/div[2]/div/div/header/div[1]/a”)).click()

    May be this may work

    Doctor Answered on September 16, 2014.
    Add Comment

    to anu17:

    Exception in thread “main” java.lang.Error: Unresolved compilation problems:
    drive cannot be resolved
    The method xpath(String) in the type By is not applicable for the arguments ()
    Syntax error on token “Invalid Character”, ) expected
    html cannot be resolved to a variable
    body cannot be resolved to a variable
    div cannot be resolved to a variable
    div cannot be resolved to a variable
    div cannot be resolved to a variable
    header cannot be resolved to a variable
    div cannot be resolved to a variable
    The method a() is undefined for the type FirstTestCase
    Syntax error on token “Invalid Character”, ( expected
    Syntax error, insert “;” to complete Statement

    at automationFramework.FirstTestCase.main(FirstTestCase.java:54)

    Default Answered on September 16, 2014.

    Hi Ohwweee,

    I tried the same code
    Thread.sleep(1000);
    drive.findElement(By.xpath(“/html/body/div[2]/div/div/header/div[1]/a”)).click();

    It worked for me with no errors.
    May be you have copy and paste the code…sometimes it wont work

    .//*[@id=’account_logout’]/a” xpath,  using this iam getting the above error

    on September 17, 2014.
    Add Comment

    Hi,

    Please check the code. It seems to be some syntax errors.

    Thanks,
    Vishal S

    Doctor Answered on September 17, 2014.
    Add Comment

    That is the question…
    http://www.toolsqa.com/selenium-webdriver/first-test-case/    –try to execute this test case

    Default Answered on September 17, 2014.

    hi ohwweee

    you must be having syntax errors in your program
    try pasting your code here to find the exact solution

    thanks
    ankit

    on September 18, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.