Can't use returned element as argument to .execute
DanielSmedegaardBuus opened this issue · 2 comments
Hey :)
I may just be retarded here, but I'm going a bit loco with this problem of mine. I'm trying to manipulate a DOM element in the browser with .execute('my code', [myElement]) and failing miserably with wd-sync.
Working code with vanilla wd:
browser.elementByCssSelector('h1', function (e, elem) {
console.log(elem);
browser.execute('arguments[0].className += " hidden"', [elem]);
});
Equivalent non-working wd-sync code:
var elem = browser.elementByCssSelector('h1');
console.log(elem);
browser.execute('arguments[0].className += " hidden"', [elem]);
The vanilla wd code adds the class as suspected, while the wd-sync code halts execution without errors (equivalent to a process.exit()) without doing anything with the DOM.
I can do browser.execute('console.log(arguments)', [3, 'nice', 'arguments']);
with wd-sync, but as soon as I try to pass an element along, it breaks down.
I note that the console.log(el)
output is significantly different between the two. Vanilla wd:
{ value: '0',
browser:
EventEmitter {
domain:
Domain {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
members: [] },
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
configUrl:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: '127.0.0.1:4444',
port: '4444',
hostname: '127.0.0.1',
hash: null,
search: '',
query: {},
pathname: '/wd/hub',
path: '/wd/hub',
href: 'http://127.0.0.1:4444/wd/hub' },
sauceRestRoot: 'https://saucelabs.com/rest/v1',
noAuthConfigUrl:
Url {
protocol: 'http:',
slashes: true,
host: '127.0.0.1:4444',
port: '4444',
hostname: '127.0.0.1',
hash: null,
search: null,
query: null,
pathname: '/wd/hub',
path: '/wd/hub',
href: 'http://127.0.0.1:4444/wd/hub' },
defaultCapabilities:
{ browserName: 'firefox',
version: '',
javascriptEnabled: true,
platform: 'ANY' },
_httpConfig:
{ timeout: undefined,
retries: 3,
retryDelay: 15,
baseUrl: undefined,
proxy: undefined },
sessionID: '80a45e74-0bc9-4b89-b62e-210724d93b74' } }
And wd-sync:
{ emit: [Function],
toString: [Function],
toJSON: [Function],
type: [Function],
keys: [Function],
sendKeys: [Function],
click: [Function],
tap: [Function],
doubleclick: [Function],
doubleClick: [Function],
moveTo: [Function],
flick: [Function],
text: [Function],
textPresent: [Function],
getAttribute: [Function],
getTagName: [Function],
isDisplayed: [Function],
displayed: [Function],
isSelected: [Function],
selected: [Function],
isEnabled: [Function],
enabled: [Function],
isVisible: [Function],
getLocation: [Function],
getLocationInView: [Function],
getSize: [Function],
getValue: [Function],
getComputedCss: [Function],
getComputedCSS: [Function],
clear: [Function],
submit: [Function],
elementByClassName: [Function],
elementsByClassName: [Function],
elementByCssSelector: [Function],
elementsByCssSelector: [Function],
elementById: [Function],
elementsById: [Function],
elementByName: [Function],
elementsByName: [Function],
elementByLinkText: [Function],
elementsByLinkText: [Function],
elementByPartialLinkText: [Function],
elementsByPartialLinkText: [Function],
elementByTagName: [Function],
elementsByTagName: [Function],
elementByXPath: [Function],
elementsByXPath: [Function],
elementByCss: [Function],
elementsByCss: [Function],
elementByIosUIAutomation: [Function],
elementsByIosUIAutomation: [Function],
elementByAndroidUIAutomator: [Function],
elementsByAndroidUIAutomator: [Function],
elementByAccessibilityId: [Function],
elementsByAccessibilityId: [Function],
element: [Function],
elements: [Function],
equals: [Function],
sleep: [Function],
noop: [Function],
performTouch: [Function],
performTouchAction: [Function],
performMultiTouch: [Function],
performMultiTouchAction: [Function],
rotate: [Function],
setImmediateValueInApp: [Function],
setImmediateValue: [Function] }
What's going wrong here?
Thanks :)
FYI: When using vanilla wd I'm using the module that is pulled in by wd-sync's package.json, so it's the same underlying code.
Okay, I've located the problem. It's the automagic wrapping of returned elements mangling the original element so that wd breaks when receiving this wrapped thingamjig. I'm creating a work-around and adding a pull request shortly.
Created what I think is a sensible work-around and created a pull request :)