How do you add a Hyperlink to a word document using an existing bookmark. I have been testing using IRB but continue to get Command Failed.
I have attached to a running word application have text selected that I want to tie to the hyperlink. For testing I have been trying to just add a google hyperlnk. I figure once I get that then I would be able to figure out the bookmark. This is the command I am using
doc.Hyperlink.add(word.selection, 'http://www.google.com', '','','text to display')
The two blank parms are for SubAddress and ScreenTip respectivly.
Luke-
You're very close...
Change this...
doc.Hyperlink.add(word.selection, 'http://www.google.com', '','','text to display')
...to this...
doc.Hyperlinks.add(word.selection.Range, 'http://www.google.com', '','','text to display')
There were two changes necessary:
(1) You call the Add method on the Hyperlinks (plural) collection, and (2) the first argument needs to be a Range object.
With these changes, your code works for me.
Related
I want to click at the end of text for text-box and write some text there. when I use .keys() it begins to append in middle
This might work in selenium Sendkeys but not in Nightwatch js as far as I know.
You can achieve what you are trying to do by doing the below steps.
Read the current value in the field
Append the text you want to add
Clear the content of the field
Keys can be used to set the full text into the field.
Did you try to use .setValue() ?
From the API link https://nightwatchjs.org/api/setValue.html:
setValue does not clear the existing value of the element. To do so,
use the clearValue() command.
May you help me in this matter, pls?
I would like to be able to delete all my files, but I would like to use a loop structure. How could I do this using the foreach in ruby, using the capybara? I've tried several posts and I did not get the expected result.
enter image description here
Delete File
Assuming there are no other buttons with the the class File__Button, you should be able to do something like:
page.all(:css, 'button.File__Button').each do |button_element|
button_element.click
end
If there is a confirmation, you will need to click that as well.
I am trying to get TinyMCE 4's image_list to work with a URL returning JSON data as specified in the example here.
I have setup a GET endpoint http://demo.com/media on my server which gives back a JSON response consisting of a list of objects with their title and value attributes set, for example:
[{"title":"demo.jpg","value":"http://demo.com/demo.jpg"}]
I have also specified the option image_list: "http://demo.com/media" when initializing the plugin.
However, when I click the image icon in the toolbar, nothing pops up. All I can see in the network tab is an OPTIONS request with status 200, but then nothing. The GET request I was expecting never happens.
What is the correct way of using image_list in TinyMCE 4? Also, does anyone have a working demo example? I couldn't find anything.
It is somewhat hard to say what the issue is without seeing the exact data your URL is returning. I have created a TinyMCE Fiddle to show (in general) how this is supposed to work:
http://fiddle.tinymce.com/pwgaab
There is a JavaScript variable at the top (pretendFetchedData) that simulates what you would grab from the server (an array of JavaScript objects) and that is referenced via image_list.
If you enter your URL (http://demo.com/media) into a browser window what is returned? Are you sure its an array of JavaScript objects?
I have the identical problem. No matter what I do with the detail of the format (e.g. putting quotes round title and value), nothing happens.
I guess the only way (for me anyway) is to insert the list into the script with php before sending the web page.
I have a situation where I am cloning an element containing a CKEditor instance. After cloning, I change all the ids to make sure I don't have two elements with the same id in the same page. I am having trouble accessing the cloned version of the CKEditor. Indeed, if I access it via the elements id, I get the original (not the clone with the new id). I can access the replaced textarea without problem, but not the CKEditor.editor object that goes along with it. Is it possible to access this object by using the replaced element (and not its id)?
N.B Please tell me what I can add here to make the question clearer...
Follow up
I figured out that I was thining about this the wrong way. When I clone the element containing the CKEditor, I have a copy of the element, but the CKEDITOR object doesn't know about it. What I ended up doing is simply removing the html associated to the cloned editor and calling CKEDITOR.replace again to replace the cloned textarea. I hope this is understandable, I don't have much time to write. If things are unclear, leave a comment and I will clarify soon.
If you are using the jQuery adapter, you can get the CKEDITOR object using the following...
$(element).ckeditorGet();
I'm not 100% on what the question is, but here is something that may help, if you have a textarea with id "content" and you replace it with the editor then you can access the instance from CKEDITOR.instances as:
CKEDITOR.instances.content OR
CKEDITOR.instances[content] OR
CKEDITOR.instances["content"]
Now when you change the id of the cloned text area to lets say "content2" and the clone editor instance is not in CKEDITOR.instances then you need to replace the clone after the id is update.
CKEDITOR.replace('content2');
So the editor will have more than one instances "content" and "content2". You can loop through the instances and verify them and use the one you need.
for(x in CKEDITOR.instances){
var instance = CKEDITOR.instances[x];
// do something with the instance
}
Does anyone know how to delete an element from the source using Watir? There doesn't seem to be a method for removing elements. Perhaps I'm missing something.
If you know JavaScript, you could execute any JavaScript code on the page.
Example:
browser.execute_script("some javascript code")
I am not a JavaScript ninja, but this question could help you: JavaScript: remove element by id.
Remove elements by css:
browser.execute_script("[...document.querySelectorAll('.some.class')].map(e => {e.parentNode.removeChild(e)})")
We can remove it with javascript. Here's an example to remove a breadcrumbs div element but it's id:
browser.execute_script("bd = document.getElementById('breadcrumbs'); bd.parentNode.removeChild(bd);")
The Purpose for Watir is to do web testing, which is to say drive the browser as if a user was interacting with it. That means doing the things a user could do, clicking on stuff, filling in input fields, etc. It also means being able to verify what is there on the screen that the user can see or interact with.
Since a user cannot delete elements, there is no means by which to do that using the tool.
If the application provides a way for users to 'remove' or 'delete' something, like closing a simulated window, removing a tab etc, then you need to do that by simulating what the user would do (usually clicking on some specific element) in order for that to happen.