I am trying to clear a text field using this action:
emailField.sendKeys("gmail.com");
emailField.sendKeys(Keys.CONTROL,"a",Keys.DELETE);
In above code, the last line only selects the text, does not delete it, but if I separate the actions it works.
emailField.sendKeys(Keys.CONTROL,"a");
emailField.sendKeys(Keys.DELETE);
From the JavaDoc for WebElement.clear():
If this element is a text entry element, this will clear the value.
Has no effect on other elements. Text entry elements are INPUT and
TEXTAREA elements. Note that the events fired by this event may not be
as you'd expect. In particular, we don't fire any keyboard or mouse
events. If you want to ensure keyboard events are fired, consider
using something like sendKeys(CharSequence) with the backspace key. To
ensure you get a change event, consider following with a call to
sendKeys(CharSequence) with the tab key.
Most likely you simply need to call:
emailField.sendKeys("gmail.com");
emailField.clear();
But if you need the clearing to be done via the keyboard for some reason, use Keys.BACKSPACE.
keys.DELETE can not work to delete the input text,you should use keys.BACKSPACE.
emailField.sendKeys(Keys.BACKSPACE)
From the JavaDoc for Keys.chord
chord(java.lang.CharSequence... value)
Simulate pressing many keys at once in a "chord".
You should be able to use
emailField.sendKeys(Keys.chord(Keys.CONTROL,"a",Keys.DELETE));
Tested in chrome driver
WE.send_keys(' \b')
This will add space then delete it (backspace)
I use in javascript and it's working fine:
await textBox.sendKeys(value);
await textBox.sendKeys(Key.BACK_SPACE);
emailField.sendKeys(Keys.BACKSPACE)
doesn't worked for me .
I used 'Key' instead of 'Keys'
emailField.sendKeys(protractor.Key.BACKSPACE)
emailField.sendKeys(Keys.CONTROL + "a",Keys.DELETE);
In PHP:
if you use php-webdriver (https://github.com/php-webdriver/php-webdriver) you must:
use Facebook\WebDriver\WebDriverKeys AS Keys;
.
.
.
$this->driver->findElement(By::id('demo'))->sendKeys([Keys::BACKSPACE,'Any other text']);
Just adding another working C# example using the Google Chrome webdriver.
SendKeys only takes one parameter so created a string with the Crtl + A. This code sequence will select the current text in the field then delete the text.
Code example:
var crtlA = Keys.Control + "a";
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(crtlA); Wait(5000); // Select current text
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(Keys.Delete); Wait(5000); // Clear current text
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(newItemSku); Wait(5000); // Input SKU name
1. in WebdriverIO, i tried to edit the text by clear text (which contains special charactes like #, +, _) in text field by below following step. Eventhough it was not successful.
example: text=> abc+1234#gmail.com
step1:browser.clearElement(selector);
step2:browser.execute(function () {
document.querySelector(>>>Cssselector<<<).value="";
});
step3: browser.doubleClick(selector);
browser.keys("Delete");
step4: browser.click(selector);
browser.keys(['Meta',a]);
browser.keys('Meta');
browser.keys('Delete');
Note: below step is resolved this issue.
var count= browser.getAttribute(selector, value).length;
for (var i=0;i<count;i++)
{
if (browser.getAttribute(selector, value)=='')
break;
}
else
{
browser.doubleClick(selector);
browser.keys("Delete");
}
browser.pause(200);
// it will clear your text field easily.
Note:
You can add the new text now.
Related
I'm adding a custom attribute that is an enum list to some of my nodes. I can easily do this with addAttr. But I don't see a way to later add a new enum value or change the enum list. Is that possible?
I have found a way to do this but it seems there should be an easier way. For my workaround, if the attribute exists I grab its value and delete the attribute. Then I add the revised attribute back into the node and set its value to the old value. By changing $enumValues I can edit the list of enums. (Note I only plan to add values not delete values) This script demonstrates my workaround:
string $attrName = "MaterialType";
string $enumValues = "Water:Sky:Terrain:Building:Road:";
string $selected[] = `ls -sl`;
if(`size $selected` == 1)
{
string $attrFullName = $selected[0]+"."+$attrName;
$existingValue = 0;
if(attributeExists($attrName, $selected[0]))
{
$existingValue = `getAttr $attrFullName`;
deleteAttr $attrFullName;
}
addAttr -ln $attrName -at "enum" -en $enumValues $selected;
setAttr $attrFullName $existingValue;
}
else
{
print "You must have 1 object and only 1 object selected\n";
};
Worth mentioning, if I run this script it does change the enum's values but these changes don't show up in Maya's interface until I close the file and reopen the file.
Any suggestions on how to do this more gracefully would be appreciated.
I might be a bit late, but you can use the "-edit" flag in addAttr.
addAttr -edit -enumNames "A:B:C" "node.enumAttrName"
However, you still need to refresh manually or with refreshEditorTemplates
Edit:
You might also want to consider optionMenuGrp. You can add menuItems via the -parent flag. You can remove a specific child with the deleteUI command or remove all children with the -deleteAllItems flag in edit mode on the optionsMenuGrp.
What you're doing - deleting the attribute and re-adding -- is unfortunately the only way to do this. Maya enums are pretty lame.
The attribute should be working correctly after the script is done - you may need to deselect and reselect it to properly refresh the attribute editor. You can check it with an listAttr -ud on your object after the script runs - you should see your attribute name in the results, even if the UI has not refreshed.
We decided to change our backend CMS to use text-angular's WYSIWYG editor. The content pulls from the database just fine, it gets rendered just fine, but the instant we go to view the HTML source, the text is there for an instant and then it disappears. I've turned off sanitization with the ta-unsafe-sanitizer="true" . The weird thing is, if I manually step through the angular code that does the digesting, eventually the text is rendered and it stays on the screen. If I run it without breakpoints, it clears the text.
I'm not sure if it is sanitization or some sort of race condition inside Angular. Anyone else run into this?
View
<div text-angular ta-toolbar="[['h1','h2','h3'],['bold','italics','underline'],['ul','ol'],['outdent','indent'],['html'],['insertImage']]" ng-model="updatePageTranslation.Content" ta-unsafe-sanitizer="true"></div>
Controller
$scope.updatePageTranslation.Content = 'large html portion here';
The scope of the form is set as follows:
<div class="widget" ng-controller="PageController">
Everything gets loaded fine and other fields of the form show the values correctly. The initial render of the content is correct. It is just when switching to HTML view that it goes blank. Clicking Html again switches back to the visual view, which is correct. But if I save, the value sent to the server is now blank.
I can even copy and paste the value into textangular.com site's demo textbox and have the same issue.
This was a strange one to figure out, but thanks to #HanletEscaño, I was able to find my way. When returning the content from the server, I had to do the following in order to pre-sanitize it so that you could switch back and forth between the HTML and rendered view:
Content.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace(" ", "");
The important one is that last replace, where we replace two spaces with nothing. This seemed to be the final trick. We were coming from a previous WYSIWYG editor where we could make the HTML look nice, but with this editor, everything has to be condensed.
As mentioned above, this seems to be due to the parser struggling to handle whitespace and newlines correctly.
If you take a look at the textAngular source, in taBind.js, _taBlankTest service seems to returns true when the bound value contains spaces, newlines etc, which in turn causes the model to get set to undefined.
I replaced mine with the following to avoid that situation:
angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'])
.service('_taBlankTest', [function(){
var INLINETAGS_NONBLANK = /<(a|abbr|acronym|bdi|bdo|big|cite|code|del|dfn|img|ins|kbd|label|map|mark|q|ruby|rp|rt|s|samp|time|tt|var)[^>]*(>|$)/i;
return function(_defaultTest){
return function(_blankVal){
if(!_blankVal) return true;
var _matchVal = _blankVal.replace(/( |\t|\n)/gm, '');
// find first non-tag match - ie start of string or after tag that is not whitespace
var _firstMatch = /(^[^<]|>)[^<]/i.exec(_matchVal);
var _firstTagIndex;
if(!_firstMatch){
// find the end of the first tag removing all the
// Don't do a global replace as that would be waaayy too long, just replace the first 4 occurences should be enough
_matchVal = _matchVal.toString().replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '');
_firstTagIndex = _matchVal.indexOf('>');
}else{
_firstTagIndex = _firstMatch.index;
}
_matchVal = _matchVal.trim().substring(_firstTagIndex, _firstTagIndex + 100);
// check for no tags entry
if(/^[^<>]+$/i.test(_matchVal)) return false;
// this regex is to match any number of whitespace only between two tags
if (_matchVal.length === 0 || _matchVal === _defaultTest || /^>(\s| |\n|\t)*<\/[^>]+>$/ig.test(_matchVal)) return true;
// this regex tests if there is a tag followed by some optional whitespace and some text after that
else if (/>\s*[^\s<]/i.test(_matchVal) || INLINETAGS_NONBLANK.test(_matchVal)) return false;
else return true;
};
};
}])
Hopefully that may help someone out there!
I am trying to enter a value into a textfield then Tab to the next field (which also enters the value). The Keys.TAB method does not seem to be working.
My code is as follows:
var Keys = JavaImporter(org.openqa.selenium.Keys)
var input = WDS.browser.findElement(pkg.By.xpath('xpath_to_input'))
input.sendKeys('value')
input.sendKeys(Keys.TAB)
I am getting the following error:
sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method org.openqa.selenium.remote.RemoteWebElement.sendKeys(string). <Unknown source>
Thank you for your help. I have tried all sorts of things and it will not work.
In addition to what ekuusela suggests there are 2 more options:
Use \t escape sequence like:
input.sendKeys('value\t');
Use java.awt.Robot approach as follows:
input.sendKeys('value')
var robot = new java.awt.Robot()
var keyEvent = java.awt.event.KeyEvent
robot.keyPress(keyEvent.VK_TAB)
robot.keyRelease(keyEvent.VK_TAB)
Remember that "Robot" approach simulates native key and mouse event on the machine where it is executed so if you use remote webdriver instance it won't play.
For more WebDriver Sampler tips and tricks see The WebDriver Sampler: Your Top 10 Questions Answered guide.
If you use Java 6 you must pass the string in an array, like this:
var input = WDS.browser.findElement(pkg.By.xpath('xpath_to_input'))
input.sendKeys(['value'])
input.sendKeys([Keys.TAB])
http://jmeter-plugins.org/wiki/WebDriverSampler/
I Am currently working on a project where I want to have the SpeechSynthesizer speak a text. I also want a textblock to display the words as they are spoken. This is so you can read along if you don't understand the Speech Synthesizer.
So basically the problem is that i cant find a efficient way to append every letter to a text within a textbox right when its spoken by the Speech Synthesizer. So it looks like the Speech Synthesizer is typing along with what he is saying.
Example
If I would do this:
SpeechSynthesizer x = new SpeechSynthesizer();
x.SpeakAsync("Hello there");
I want the textbox text to write along as the words are spoken by the x (SpeechSynthesizer ). Something like this:
http://youtu.be/hx6JL7PsLrg?t=1m56s
As Eric mentioned, you have to use the SpeechSynthesizer.SpeakProgress event:
For Example:
var ss = new SpeechSynthesizer();
ss.SpeakProgress += (sender, args) => txtBox.Text += args.Text;
ss.Speak("Hello this is " + true);
This is kind of hacky (and isn't guaranteed to do letter-by-letter), but you could use the PhonemeReached event as a hint to display the next letter (and stop at word breaks) and then use the SpeakProgress event to generate the remaining letters in the word. If you're using SSML, you'll need to skip over markup, of course.
I have a view that returns search results via the search API. It performs this use case adequately and I am happy. To crown the deliverable, I need to add a title override of the form Showing search results for '%1' which looks easy enough initially but it isn't working entirely as planned.
For a URL = mysite.com/search/all?search=wombat, where the search value is gathered from an exposed form within a block, I am either getting:
Showing search results for 'Search for "all"'
or, if I enter %1 in the title override for subject not appearing in the URL, I get:
Showing search results for %1". My goal is to get "Showing search results for 'wombat'
The title override works in that it removes the Search for ... part but the substitution picks up on "all" as the exception value (or anything else that I set as the exception value) where I need to be able to pick up the value of the query string (search=wombat).
Can anyone shed some light here?
The problem is that the '%1' and '%2' that you can use to override the title refer to your path's first and second arguments (in Drupal terms) and that would be 'search' and 'all?search=wombat' in your case...
What you need instead is the 'wombat' as a path component in itself.
Perhaps you can achieve that by working that case you're talking about: the case of a "title override for subject not appearing in the URL". There is an option in the contextual filters section (I'm assuming that's where you're working) for providing a default value when one isn't present. Perhaps you can use the 'PHP code' option there, isolate your 'wombat' string and return that as a default contextual filter, and then you can get to it via the '%1'.
The php code to get that portion of the URL should look something like this:
return htmlentities($_GET['search']);
the $_GET() returns the value of that variable in the url, and the htmlentities() is just to keep it safe, since it's using a portion of the url, which is vulnerable to XSS.
See if that combo (1) setting a default argument when one isn't present and 2) using that newly set argument in your title printout) works!
I fixed this issue.
Using following two hooks we can change the defalut value of filter Programmatically.
<?php
/**
* hook_views_pre_view
* #param type $view
* #param type $display_id
* #param type $args
*/
function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'VIEW_NAME') {
$filters = $view->display_handler->get_option('filters');
$view->display_handler->override_option('filters', $filters);
}
}
/**
* hook__views_pre_build
* #param type $view
* #return type
*/
function MODULE_NAME_views_pre_build($view) {
if ($view->name=='VIEW_NAME') {
$view->display['page']->handler->handlers['filter']['filter_field']->value['value'] = 8;
return $view;
}
}
?>
This code worked for me. I am using the drupal 7.