Giter Club home page Giter Club logo

Comments (7)

illicitonion avatar illicitonion commented on May 20, 2024 1

I could certainly argue that if the element currently has focus, the caret position should not be changed. I can't remember exactly why that isn't the case, but I'm afraid it's unlikely to be changed in the spec at this point... I wonder if anyone else can remember the details here?

from webdriver.

andreastt avatar andreastt commented on May 20, 2024

Andreas Tolfsen:

This seems somewhat related to bug 29247.

from webdriver.

AlexandreBonneau avatar AlexandreBonneau commented on May 20, 2024

I'm not sure if this is entirely related or if it's the right place to report that, but one use case where the lack of text selection/caret positioning lacks is a very simple one :

  1. Set the caret position (or the selection) in the input wherever I want,
  2. Input some characters at that position,
    ...and that's it.

Currently I found a way to set the caret position, but this feels like a common use case and perhaps a built-in function (ie. setSelection(element, start, end = null)) would help.

On the other hand, sendKeys just ignores the caret position when it sends keys, so the text selection point is moot until that bug is fixed (because it looks like a bug to me, am I wrong?).

cf. real world use case here and there.

from webdriver.

illicitonion avatar illicitonion commented on May 20, 2024

You can sendKeys the HOME, END, ARROW_LEFT and ARROW_RIGHT keys, which allows you to set the carat position.

from webdriver.

AlexandreBonneau avatar AlexandreBonneau commented on May 20, 2024

Well, as a workaround to sendKeys resetting the caret position, I tried a few variations of this idea in the original codepen mentioned in the second link I pasted, line 129-131 :

browser.keys(selectors.input0, [browser.keys.LEFT_ARROW, browser.keys.LEFT_ARROW, browser.keys.LEFT_ARROW, browser.keys.LEFT_ARROW, '123']); // Not working

browser.keys(selectors.input0, ['ArrowLeft', 'ArrowLeft', 'ArrowLeft', 'ArrowLeft', '123']); // Not working

browser.keys(selectors.input0, ['\uE012', '\uE012', '\uE012', '\uE012', '123']); // Not working

but somehow none of that worked too.

Either way, I do think sendKeys should not change the caret position, don't you?

from webdriver.

AlexandreBonneau avatar AlexandreBonneau commented on May 20, 2024

@illicitonion In your comment few weeks ago, you were saying :

You can sendKeys the HOME, END, ARROW_LEFT and ARROW_RIGHT keys, which allows you to set the carat position.

Would you by any chance have a working example where a script sends at least on key to an input?

from webdriver.

shs96c avatar shs96c commented on May 20, 2024

The selenium "send keys" command sets the caret position to the end of the string to facilitate users doing interesting things in a loop from the local end: early bug reports and usage suggested they'd always want to append content rather than replace what's existing. There's a strong case for what @illicitonion suggested if the focus is already in the element, but it depends on whether we have enough time to get the implementation in place or not.

If you're using the selenium python bindings and marionette, the following should work:

import selenium.webdriver
from selenium.webdriver.common.keys import Keys

d = webdriver.Firefox()
d.get('http://www.google.com')
q = d.find_element(by = 'name', value = 'q')
q.send_keys('Hello world' + Keys.LEFT + Keys.LEFT + Keys.LEFT + Keys.LEFT + Keys.BACKSPACE + 'W')

You should see the search box contain "hello World".

These APIs are a good candidate for Level 2.

from webdriver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.