“NoSuchElementException” using Selenium Webdriver

0 votes

Below is the simple code to click an object using xpath.

I have located the xpath and performed the desired operation but still "NoSuchElementException" is thrown.

String localobject=OR.getProperty(object); //Obtaining xpath from object repository

we = driver.findElement(By.xpath(""+localobject+"")); 

executor.executeScript("arguments[0].click();", we);

Below is the trace:

org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #\/\/\*\[text\(\)\=\'Log\ Out\'\]

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

Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:22.379Z'

System info: host: 'xxxxxxxx', ip: 'xx.xx.xx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'

Driver info: org.openqa.selenium.ie.InternetExplorerDriver

Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:17221/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}

Session ID: 1617a9c2-cd03-4c77-8732-c4951fd83729

*** Element info: {Using=id, value=//*[text()='Log Out']}

    at sun.reflect.GeneratedConstructorAccessor32.newInstance(Unknown Source)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

    at java.lang.reflect.Constructor.newInstance(Unknown Source)

    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)

    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)

    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)

    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)

    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)

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

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

    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:417)

    at org.openqa.selenium.By$ById.findElement(By.java:218)

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

    at config.Keywords.click(Keywords.java:129)

    at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at executionEngine.DriverScript.execute_Actions(DriverScript.java:123)

    at executionEngine.DriverScript.execute_TestCase(DriverScript.java:106)

    at executionEngine.DriverScript.main(DriverScript.java:57)

Jul 27, 2018 in Selenium by Martin
• 4,210 points
455 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

When you obtain the xpath from object repository ensure that you invoke it as a String as follows :

we = driver.findElement(By.xpath(localobject));

Your error will help you:

The expression #//*[text()\=\'Log\ Out\'] is definitely not a valid css selector. Currently CSS_Selectors doesn't supports text() attribute.

Again the expression //*[text()='Log Out'] is not a valid id but a potential xpath

answered Jul 27, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
474 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,223 views
0 votes
1 answer

Double click a record in a grid using Selenium webdriver

Try Actions class to perform this Actions action ...READ MORE

answered Mar 29, 2018 in Selenium by Damon Salvatore
• 5,250 points
591 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
66 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
438 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
52 views
0 votes
1 answer

Firefox browser not opening with given URL using Selenium Webdriver with Java

Download the latest selenium jar and replace ...READ MORE

answered Apr 30, 2018 in Selenium by Samarpit
• 5,130 points
1,536 views
0 votes
1 answer

Maximizing the browser window in Selenium WebDriver using C#

Check this first: http://code.google.com/p/selenium/issues/detail?id=174 You Can use the JavascriptExector as follows: public ...READ MORE

answered May 2, 2018 in Selenium by Samarpit
• 5,130 points
45 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.