elementIdLocation/elementIdLocationInView not working
I'm trying simple test to find the location of the given selector.
But the method seems not working, instead throwing Runtime error.
Here is my stack trace below,
Selenium 2.0/webdriver protocol bindings implementation with helper commands in nodejs.
For a complete list of commands, visit http://webdriver.io/docs.html.
[12:39:28]: COMMAND POST "/wd/hub/session" [12:39:29]: SET SESSION ID 4d13d391-9f21-4508-88cc-5933d46fc476 [12:39:29]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/timeouts/implicit_wait" [12:39:29]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/timeouts/async_script" [12:39:29]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/url" [12:39:31]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/window/current/size" [12:39:31]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/elements" [12:39:32]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element/0/clear" [12:39:32]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element/0/value" [12:39:32]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/elements" [12:39:32]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element/1/clear" [12:39:32]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element/1/value" [12:39:32]: COMMAND GET "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element/" Callstack: -> elementIdLocation("#login-button") ] message: 'RuntimeError (UnknownError:13) An unknown server-side error occurred while processing the command. Problem: GET /session/4d13d391-9f21-4508-88cc-5933d46fc476/element/ Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03' System info: host: 'abc', ip: '0.1.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.3', java.version: '1.6.0_65'\nDriver info: driver.version: unknown\u001b[1;30m
Callstack: -> elementIdLocation("#login-button"), name: 'RuntimeError', hasCallStack: true } [12:39:34]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element" [12:39:34]: COMMAND POST "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element/2/click" [12:39:44]: COMMAND GET "/wd/hub/session/4d13d391-9f21-4508-88cc-5933d46fc476/element/"
Callstack:
-> elementIdSize("#login-button")
]
message: 'RuntimeError
(UnknownError:13) An unknown server-side error occurred while processing the command.
Problem: GET /session/4d13d391-9f21-4508-88cc-5933d46fc476/element/
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03
System info: host: 'abc', ip: '0.1.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.3', java.version: '1.6.0_65'
Driver info: driver.version: unknown\u001b[1;30m
Callstack:
-> elementIdSize("#login-button"),
name: 'RuntimeError',
hasCallStack: true }
ahh I see .. elementIdLocation and elementIdLocationInView are protocol commands and need the
ID of a WebElement JSON object to route the command to
You are passing a CSS selector instead. WebdriverIO provides two counterpart commands for these protocol commands which resolve the CSS selector before calling elementIdLocation. Have a look on getLocation and getLocationInView
I tried getLocation, but then it throws me an error method not found
hum .. weird. Try to test the following. It should give you a list of all div locations on the page:
var client = require('webdriverio').remote({
desiredCapabilities: {
browserName: 'phantomjs'
}
});
client
.init()
.url('http://github.com')
.getLocation('div', function(err, location) {
console.log(location)
})
.end()
Thanks! It worked.
How can I get the location of the text on the page? all I have is element tagName associated with it.. any idea?
What do you mean exactly?
I meant, is there any CSS selector webdriverio supports which can query for text or label on the page.
For e.g:
Hello Webdriver
So now I wants to get the location(x,y) of the text "Hello Webdriver" on the page, how can I do it? Any idea..
There is no Selenium selector strategy that enables this functionality. You can query link texts but thats it. You are looking for a :contains() selector right?
If the containing text is the only hint to the element you want to interact with, I would suggest you query the source of the document and apply some regex magic on it to find the parent element.
Sure, I'll give a try.
Thanks! :)
How do I get hold of document and window object??
You can inject javascript via execute command to get informations about these objects. They are not accessible with Selenium though since you don't interact with them.
I tried,
client.execute('return window();',function(err,value){
console.log(value);
})
but returns me: RuntimeError.....
what are you trying to achieve? window is an object not a function. See https://developer.mozilla.org/en-US/docs/Web/API/Window
My bad, I meant return window;
You can't return the whole window object, only specific attributes (basically everything you can parse into a JSON object)