Comments (7)
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.
Andreas Tolfsen:
This seems somewhat related to bug 29247.
from webdriver.
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 :
- Set the caret position (or the selection) in the input wherever I want,
- 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.
You can sendKeys the HOME, END, ARROW_LEFT and ARROW_RIGHT keys, which allows you to set the carat position.
from webdriver.
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.
@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.
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)
- Error 405 when trying to run a simple swipe test HOT 1
- W3C WebDriver
- Clarify how the double click tracking should work in the actions
- Update commit reference for Selenium atoms HOT 2
- Rational for this key? HOT 2
- Move "Get Title" into "Document" section. HOT 3
- Consider introducing per-Element script execution.
- Consider introducing some kind of interface for resetting a session. HOT 6
- Spec: 12.5.1 Element Click: "pointer up action" is not used HOT 1
- What's a "user prompt"?
- Update commit reference for Selenium atoms (follow-up from issue #1773)
- Safari is unable to get text from components with Shadow DOM HOT 2
- RCS WebdriverInstaller
- webdriver
- Allow uploading folders HOT 1
- Output-only capabilities HOT 1
- setWindowRect should be matched as a capability HOT 7
- Add ability to save autofill data and trigger autofill on form elements HOT 6
- w3c wheel actions sometimes can't perform deltaX,deltaY movement HOT 1
- "Run the post navigation checks" doesn't make sense
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webdriver.