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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

According 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