|
42 | 42 | } |
43 | 43 | } |
44 | 44 |
|
| 45 | + function getXPath(node, path) { |
| 46 | + path = path || []; |
| 47 | + if(node.parentNode) { |
| 48 | + path = getXPath(node.parentNode, path); |
| 49 | + } |
| 50 | + |
| 51 | + if(node.previousSibling) { |
| 52 | + var count = 1; |
| 53 | + var sibling = node.previousSibling |
| 54 | + do { |
| 55 | + if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {count++;} |
| 56 | + sibling = sibling.previousSibling; |
| 57 | + } while(sibling); |
| 58 | + if(count == 1) {count = null;} |
| 59 | + } else if(node.nextSibling) { |
| 60 | + var sibling = node.nextSibling; |
| 61 | + do { |
| 62 | + if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) { |
| 63 | + var count = 1; |
| 64 | + sibling = null; |
| 65 | + } else { |
| 66 | + var count = null; |
| 67 | + sibling = sibling.previousSibling; |
| 68 | + } |
| 69 | + } while(sibling); |
| 70 | + } |
| 71 | + |
| 72 | + if(node.nodeType == 1) { |
| 73 | + path.push(node.nodeName.toLowerCase() + (node.id ? "[@id='"+node.id+"']" : count > 0 ? "["+count+"]" : '')); |
| 74 | + } |
| 75 | + return path; |
| 76 | + } |
| 77 | + |
45 | 78 | webdriver.WebDriver.prototype.visualizerGetSource = function() { |
46 | 79 | webdriver.http.Executor.COMMAND_MAP_['visualizerGetSource'] = { |
47 | 80 | method: 'GET', path: '/session/:sessionId/-cisco-visualizer_source'}; |
|
297 | 330 | return false; |
298 | 331 | } |
299 | 332 |
|
300 | | - var hostSize = {width: win.innerWidth, height: win.innerHeight}; |
301 | | - |
302 | | - self.driver.manage().window().getSize().then(function(targetSize) { |
303 | | - var targetDoc = self.driver.findElement(webdriver.By.xpath('/html')); |
304 | | - var x = Math.floor(event.clientX * targetSize.width / hostSize.width); |
305 | | - var y = Math.floor(event.clientY * targetSize.height / hostSize.height); |
306 | | - return self.driver.actions(). |
307 | | - mouseMove(targetDoc, {x: x, y: y}). |
308 | | - click(event.button). |
309 | | - perform(); |
310 | | - }).then(function() { |
| 333 | + var xpath = getXPath(event.target); |
| 334 | + xpath = '/' + xpath.join('/'); |
| 335 | + var target = self.driver.findElement(webdriver.By.xpath(xpath)); |
| 336 | + self.driver.actions(). |
| 337 | + mouseMove(target, {x: event.offsetX, y: event.offsetY}). |
| 338 | + click(event.button). |
| 339 | + perform(). |
| 340 | + then(function() { |
311 | 341 | return self.driver.visualizerShowPoint(); |
312 | 342 | }).then(function() { |
313 | 343 | // self.updateSource(); |
|
0 commit comments