Protractor - text selection

I have some real problems with selecting any text using a protractor.

Small context; this is for the AngularJS CMS system for writing news articles. The text I want to highlight is in the text area, which is most of the page. A similar application is a Google Docs Doc.

With webdriver, I believe I can just use something:

browser.actions().keyDown(protractor.Key.CTRL).sendKeys('a').perform();

However, I am code on a MAC, and although our tests are currently running on a Windows window in SauceLabs, the ultimate goal is to switch to a MAC to emulate our users.

I tried a similar line of code, but with Command (or CMD), but it doesn’t work, according to this post , OSX doesn't support native key events.

Other methods I learned:

  • Trying to triple click in an element to select all the text ... but I couldn’t get this to work (any help?). This is complicated by the fact that the mouse cursor must be above the text so that it selects all the text.

  • Double-clicking inside the field, which on my local machine manages to select the last job in the text area, but in SauceLabs, the browser is smaller, so I can choose another word. This seems too fragile to use, as it will be different on most machines.

  • Move the text cursor to the beginning or end of the text area, press the Shift key, and press the left or right arrow keys depending on the number of characters in the text area. I had a problem moving the cursor to the beginning or end of a text field in this implementation.

, , ! , , , !

+4
4

, , .executeScript.

, , , .

, , :

Article.prototype.selectFirstParagraph = function(driver) {
    driver.executeScript(function () {
        var range = document.createRange();
        range.selectNode(document.body.querySelector('.ui-rich-text-editor__input').firstChild);
        var sel = window.getSelection();
        sel.removeAllRanges();
        sel.addRange(range);
        return sel;
    });
}
+2

, .

var Key = protractor.Key;
var Key = protractor.Key;
browser.actions().sendKeys(Key.chord(Key.CONTROL, 's')).perform();
browser.actions().sendKeys(Key.chord(Key.CONTROL, Key.SHIFT, 'm')).perform();
browser.actions().sendKeys(Key.chord(Key.CONTROL, 'o')).perform();

+1

OSX, . issue 690

0

In the event of a problem with the Selenium driver and MacOS, the COMMAND key events will not be correctly propagated. https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/3101

0
source

All Articles