admin管理员组文章数量:1323735
I have the goal to return drop-down list of elements. I tried to do this with protractor's methods, but I hadn't found easy ways for searching isolate-span elements. On that reason I want to use javasript code:
var my_js_element = browser.executeScript(jQuery("td.ng-binding>div.b-bobox.ps-list-drop-single-autoplete.ng-isolate-scope.ng-pristine.ng-required.ng-invalid.ng-invalid-required").isolateScope().psListDrop.toggleVisible(true).element);
But it isn't working. And I'm not sure that I can return elements with this method. Is it true? Or maybe somebody know how I can do this?
I have the goal to return drop-down list of elements. I tried to do this with protractor's methods, but I hadn't found easy ways for searching isolate-span elements. On that reason I want to use javasript code:
var my_js_element = browser.executeScript(jQuery("td.ng-binding>div.b-bobox.ps-list-drop-single-autoplete.ng-isolate-scope.ng-pristine.ng-required.ng-invalid.ng-invalid-required").isolateScope().psListDrop.toggleVisible(true).element);
But it isn't working. And I'm not sure that I can return elements with this method. Is it true? Or maybe somebody know how I can do this?
Share Improve this question asked Jul 16, 2015 at 11:48 Лилия СапуринаЛилия Сапурина 6277 silver badges22 bronze badges2 Answers
Reset to default 6According to the docs of browser.executeScript
:
If the script has a return value (i.e. if the script contains a return statement), then the following steps will be taken for resolving this functions return value: - For a HTML element, the value will resolve to a webdriver.WebElement.
From your executeScript
call you should return an HTML element, also it should be a "native" DOM element, so it could be converted to webdriver.WebElement
. Then this element is resolved via promises and is available as an argument in a callback for .then()
:
browser.executeScript(function () {
var element = jQuery('.world').get(0); // get "native" DOM node
return element; // explicit return
}).then(function (webElement) {
expect(webElement.getText()).toContain('Hello');
});
So Protractor is built ontop of the WebDriver
specification.
According to the specification, it is possible to return values from executed scripts. It just might be JSON which would require you to convert it back. You can read more here.
Try logging the value it returns. You might also explore using an XPATH selector to find your element.
Something like:
//td[class="ng-binding"]/div[class="b-bobox" and class="ps-list-drop ...]
本文标签: javascriptProtractor How to return element by executing js scriptStack Overflow
版权声明:本文标题:javascript - Protractor: How to return element by executing js script? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742119543a2421631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论