Searching for specific text in SmarTerm via VBA - vba

I'm looking to search for a specific line of text in a SmarTerm application window opened via VBA and then copy the rest of the row of data into a cell in a worksheet. Previously this was accomplished using a reflection session but I now have no option other than to use SmarTerm.
The code that worked with reflection is:
Found = Session.FindText("SEARCH TEXT", 0, 0)
If Found Then
str_get_string_from_reflection = .GetText(Session.FoundTextRow, 19, Session.FoundTextRow, 60)
Trim (str_get_string_from_reflection)
rng_range_constants_col_A.Offset(0,3).Value = "Search Text: " & str_get_string_from_reflection
End If
Sadly this doesn't work with the SmarTerm solution, I've tried using the Session.StringWait.MatchString command but this doesn't seem to search in the entire visible screen.
Any help that can be offered here will be very much appreciated
I've tried using the SmarTerm Macro Guide (http://www.esker.com/fm/others/eval-smarterm/bin1211/macro.pdf) but can't locate anything other than StringWait.MatchString or StringWait.MatchStringExact that supports searching in the available text. Sadly this only seems to search on the last line of the text, rather than on the whole visible screen.

You could use Session.ScreenText(row, col, page, chars)

Related

Katalon WebUI.SetMaskedText() randomly wrapping text

I have a field in a popup to enter a phone number with masked text: "( _ _ _ ) _ _ _ - _ _ _ _".
(Masked text means that we are using jquery to automatically format the text being entered. You can learn more here.) The underscores above are just to represent the spaces for the digits of the phone number. :)
Results
The code randomly wraps the text when entering. I've tried using the string as '8015558245' and masked as '(801)555-8245', both wrap randomly with the results:
(015)558-2458
(155)582-4580
(555)824-5801
The only suggestion I found on my many searches of the internets was to double click the element first, which doesn't effect the results. Each time I run the test in incognito mode. Occassionally it works, the rest of the time it fails.
Code
Here is my code:
TestObject enterPhoneNumber = findTestObject('path/PhoneNumberObject')
WebUI.doubleClick(enterPhoneNumber)
WebUI.setMaskedText(enterPhoneNumber, '8015558245')
Specs
I am using Katalon v5.9.1, but it wasn't working on earlier versions either.
Chrome is the browser.
I think this might be happening because WebUI.doubleClick() is targeting the middle of the element so it starts typing somewhere behind the ().
Maybe try using WebUI.clickOffset(enterPhoneNumber,x,y) with a small value of x and y (5 px for example - calculated from the top left corner of the element) so you are sure click will land somewhere near the first (_ _ _ digit place.
Another option is using
WebUI.click(enterPhoneNumber)
WebUI.sendKeys(enterPhoneNumber, Keys.chord(Keys.HOME))
WebUI.setMaskedText(enterPhoneNumber, '8015558245')
with
import org.openqa.selenium.Keys
imported.
The answer was a combination of things:
First: I needed to set the cursor to the left of the masked text right at the opening parenthesis. To guarentee this, I used the suggested clickOffset(enterPhoneNumber, 40, 5). [Thanks #Matt Mrse for your suggestion!]
This didn't fix the text wrapping when using WebUI.setMaskedText(..), but it allowed for the next part to work reliably, and that is:
Second: Text entered into the box manually was always entered in correctly. So instead of WebUI.setMaskedText(..), I just sent the whole string as if it were typed by using WebUI.sendKeys(..).
The final code, that worked reliably (all other previous attempts failed within 1-2 attempts) after five test runs in five different tests is this:
WebUI.clickOffset(enterPhoneNumber, 40, 5)
WebUI.sendKeys(enterPhoneNumber, '8015558245')
WebUI.delay(1) //For humans to be able to see that text was entered correctly
That's it!
Hope this helps anyone else with this issue!
I think there are something you need to double check:
- are the () be added automatically when you typing the phone number?
- setMaskText() is used to enter text as '**************'
I am not sure if I understand the case clearly. Normally, I deal with this case by using sendKeys keyword, which will demostrate the typing action so the phone format can be added correctly.

VBA Macro for MS Word to Ignore Spelling Errors in Selected Block of Text

VBA Noob here. I take my python programming notes in a word document since I can import images into it and align/format text quickly. Any code pasted into this document comes up as a spelling error. I'm trying to find a way to ignore spelling errors within a selected text area so I don't have to deal with ignoring each spelling error line of code individually. I don't want to turn off spell check in the document.
Ideally, I'd able to write a macro that read:
Selection.ShowSpellingErrors = True
but ShowSpellingErrors() can only be used with ActiveDocument. I was able to a record a macro that ignored spelling errors with:
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = True
However, any new text I type into this also doesn't get proofed, which is something I don't want. I want to be able to write new text and see any errors I make. Thanks for any help!
Not a VBA Macro, but I think this answer may be relevant to your problem anyway.
Try creating a style for code which does not include spell check. Anything with this style does not get spell checked, while the rest of the document does. Sometimes I find the code shows the red underline, but if you run spell check it should just disappear without needing to be 'fixed'.
Create a new style, in the modify formatting dialog, go to Format > Language:
Tick the 'Do not check spelling or grammar' checkbox:
Highlight your code and use the new style. Any text not in this style will still be spellchecked:

Selenium VBA code to paste data in browser

I am trying to stimulate the control+v option in a text box in chrome using selenium vba wrapper. I tried using the context click but that function seems to click at a random position based on the cursor position. I tried using the send key function but i am not getting the desired result.
selenium.SendKeys (key.Control & "v")
Please any advise or leads would be much appreciated.
You want to target the text box before using sendkeys. Let's say, hypothetically, that there is an ID called textbox1 for identifying the element then:
driver.FindElementById("textbox1").SendKeys("yourString")
Or
driver.FindElementById("textbox1").SendKeys Keys.Control, "v"
The latter assuming info is already in the clipboard with, for example, driver.SetClipBoard "yourString"
I think you'll be better off using a variable to hold your data rather than the clipboard. Then you can use sendkeys to type it in:
myData= "your data here"
selenium.sendkeys myData
hth

Vb.net Exporting Richtextbox formated content to Excel Cell

Further to my first question regarding that issue, here are my progress:
First : using the function: sheet.Cells(X, X).Value = RichTextBox1.Rtf, I find this kind of cell content:
"rtf1\ansi\ansicpg1252\deff0\deflang1036\deflangfe1036{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Calibri;}{\f2\froman\fprq2\fcharset0 Times New Roman;}}
{\colortbl ;\red255\green0\blue0;\red0\green0\blue139;}
\viewkind4\uc1\pard\f0\fs22 XXXXXXXXXXX\par
\cf1\strike\f1 XXXXXXXXXXX\par"
I can however manually use the excel function "keep the original formatting" to paste some rtf doc content into a cell.
Could you help me find a way to use this function in the VB.net code if possible?

Insert image from URL bookmark Microsoft word

I have a image URL contained in my sql database.
I create a bookmark for that column in the word document (this works fine).
Now I want to use the image URL that is passed from the database to insert an image.
I have tried hyperlink (does not work and does not display image).
I have tried Quick Parts - IncludePicture (does not work).
I have been Googleing and have not found anything that works.
Ok let me simplify this.
I want to insert a image using an URL.
You can do this in alot of different ways I know.
For instance using Quick Parts and the selecting IncludePicture you would the past the URL of the picture and BAM image inserted.
Now I want to do exactly that with one exception. The URL is a microsoft word bookmark that I get from my database.
For some reason this does not want to work. I have also checked the bookmark data and it is correct and yes it is a valid URL because if I copy and paste it from the database in the way I described above it works.
So is there any other way to do this?
To be honest I still don't know where is exactly your problem. I assumed that you have knowledge and code to take both bookmark name and url from your database using VBA. If so, there would be quite simple code which would allow you to load picture from web to bookmark in your word document.
Below is the code I have tested with half of success. If I add any picture it will work fine. But will not work with url of active google map. I have no idea what you you mean with 'static google map' (in comment), you didn't provide any example therefore you need to make your own test.
Before you run this for test be sure you have two bookmarks in your active document: bookmark_logo and bookmark_poland. Hope this will help a bit.
Sub Insert_picture_To_Bookmark()
Dim mapURL As String
Dim soLOGO As String
soLOGO = "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png"
ActiveDocument.Bookmarks("bookmark_logo"). _
Range.InlineShapes.AddPicture _
soLOGO, True, True
mapURL = "https://maps.google.pl/maps?q=poland&hl=pl&sll=50.046766,20.004863&sspn=0.22047,0.617294&t=h&hnear=Polska&z=6"
ActiveDocument.Bookmarks("bookmark_poland"). _
Range.InlineShapes.AddPicture _
mapURL, True, True
End Sub