I have a UIWebView displaying string containing a locally generated sequence of Korean and Russian words. I.e. there is nothing special in the string, just simple 'body'/'span' tags to format the text.
I need to get selected text, so I use:
NSString *selected = [articleWebView stringByEvaluatingJavaScriptFromString:#"document.getSelection()"];
This returns nothing: NSLog (#"%#", selected); logs out nothing.
What can be a problem here? I haven't found anyone here having similar problem and it's driving me nuts. Please, help.
OK, I've got it. The following works just fine:
NSString *selection = [articleWebView
stringByEvaluatingJavaScriptFromString:#"window.getSelection().toString()"];
Use this, not that.
Related
I am looking for a method in velocity where I can put a check on certain part of string and carry on with subsequent methods. I tried with the following:
But it throws an error that 'contains' function is unrecognized.
##Check whether a certain string is a sub part of other string
#set($Name="")
#set($SomeName="ABC DEF"
#set($Name=$SomeName)
#if($Name.contains("DE"))
Correct!
#end
At first glance i found that there is a mistake bracket not close
#set($SomeName="ABC DEF"
should be changed to
#set($SomeName="ABC DEF")
Other than that i don't think there is a problem with contains function . i have tested it is working fine with me .
I know that there are a lot of posts like this but I read them and my application does not work yet.
Im trying to convert TextView parameter into int.
I use this:
int MyScore;
TextView score = (TextView) findViewById(R.id.highscore);
MyScore = Integer.parseInt(score.toString());
When im launching the program and rich to the place this should work my program crushing becasue of the last line: MyScore = Integer.parseInt(score.toString());
How can I solve this?
Your last line should read
MyScore = Integer.parseInt(score.getText().toString());
The toString() method called on your score object describes the score object, it does not return the string entered into the score object. Please refer to the Oracle Java tutorials. It is a good idea to read through most of them.
Because you didn't specify the language used I cannot answer fully, but I can guess what the problem is. Most input fields have a value or text property, try parsing that.
variableName = driver.findElement(By.XPath(".//*[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]"))
Running the above always seems to lead to the error:
Why is this? I always see other people using findElement By XPath. If it helps, I generated about half of my code using Selenium's 'record' feature. I then converted the code into 'VBA/Webdriver' before pasting it into Excel to use as a Macro.
What exactly is wrong with my code? I have used findElement a number of times before, so I'd have to guess that the problem is with the By.XPath part of my code... Is there any way around this?
Edit: Even variableName = driver.findElementsByXPath(".//*[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]") leads to the error 'Invalid procedure call or argument' even though it looks fine to me.
Try:
variableName = driver.findElementByXPath("//div[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]")
Notice that I removed the . in the beginning of the xPath and replaced * with div. Also, you're missing something at the end. You are just declaring the path here and not really getting a value.
EDIT: Referring to just the xPath is not usually enough. Do you want to perform an action on it, get the text inside, the tagname, etc.?
EDIT2: Testing to get the .Text attribute returns a "findElement By XPath not supported in Selenium VBA?" message.
Here's what works for me:
Dim variableName() as variant
variableName = driver.findElementsByXPath("//div[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]").getdata
Notice it's "find elements [plural] by XPath". This creates a two-dimensional array. variableName(1,1) will have the data you're looking for.
(I know it's been more than 6 years, but it's my first contribution and I can't resist! Maybe that can help someone else)
You have to initialise the following:
Dim By As New By, variableName As WebElement
and because variableName is an object, it has to be declared, as follows:
Set variableName = driver.FindElement(By.Xpath(".//*[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]"))
I have text file in VB6 Application resources, and I am trying to read the text in it.
How to do that? I have been searching for hours without a proper solution. Somebody please help me.
My code is:
Private Sub Command1_Click()
Dim URL As String
URL = LoadResString(101)
MsgBox URL
End Sub
This maybe explains it more: http://i.imgur.com/wGnWCBb.jpg
Is this even possible? Somebody please spoonfeed me, I would appreciate that a lot.
I am trying to read the string from resource to a variable(string) and then prompt it with messagebox.
Some simple solution would be great. Also, if this is possible with FindResource API, please tell me how or point me to the right direction.
I had to do something like this many years ago.
I used s = StrConv(LoadResData(resId, resType), vbUnicode). The resource was an ANSI (non-unicode) file.
resType was a custom type I just made up when I saved the resource.
I had an issue with a double null that got appended at the end of the text, and which had to be removed. I can't remember the exact reason why that happens, but I presume it has to do with the resource being stored as a double-null-terminated list of C-strings.
If I had to guess, you'll have better luck with LoadResData(). Make sure to use both parameters (the id and type ones).
I have an NSMutableArray miniResults which contains the following NSStrings.
List 1, Some strings have German umlauts.
After putting miniResults into NSString solution with this:
solution = [NSString stringWithFormat:#"%#",miniResults];
solution contains converted strings what I don´t want.
List 2, All umlauts converted!
I don´t see why this happens.
What am I doing wrong?
Any ideas?
The compiler seems to escape them to unicode. Shouldn't be a problem anyfurther. I've got no sources for this, but it looks like that.
One possible fast solution would be substituting them. Make "Ae" from "Ä", etc.