OpenQA.Selenium.IWebElement.Text
If you call Text Property and the HTML inner Text is "❌", you will get ":x:".
If you take this Text "✅", the Return Value is ":white_check_mark:".
I looked up different Emoji and Unicode References, but I could find, which code/charset this is.
A Solution for me would be
If there is a method with the original Text as return value.
or if there is a library/packed, converting the code back to Unicode.
Code
string cItemText = cItem.FindElement(By.ClassName("im_message_photo_caption")).Text;
Update
Found out, that this code :white_check_mark:, is something called shortcode/shortcodes, but no clue how to convert back to unicode.
Did you tried below code to get the unicode ?
Add a reference to Microsoft.JScript.dll
string result = Microsoft.JScript.GlobalObject.escape(inputString);
https://social.msdn.microsoft.com/Forums/vstudio/en-US/9a09cb14-5eb3-4b74-9cf1-ac9e0ae641fc/convert-string-to-unicode?forum=csharpgeneral
Related
I m trying to click on value (link format) on a webpage and i read it from a separate file. the value is read correctly from the external file but I cant get the script to click on it. the first line of code reads the value correctly from the external file but the second is supposed to click on the rendered value. So for instance, the text file has one value of X1 and the webpage has a value in link format called X1. So the idea is to click on the X1 link using the variable valueID rather than just reading the text link from the page. any idea how to implement it or get it to work with the code below please?
<pre>
string ValueID = System.IO.File.ReadAllText(#"ValueID.txt");
await _page.ClickAsync("Value=ValueID");
</pre>
The following code should work:
string ValueID = System.IO.File.ReadAllText(#"ValueID.txt");
await _page.ClickAsync($"text={ValueID}");
Notice that you are including the string interpolation operator inside your string, whereas it should be in front of it, e.g. $"text={ValueID}" instead of "text=${ValueID}", but if the above doesn't work, for some reason, also try the following:
when you're reading the value from the text file, make sure there are no leading or trailing whitespace characters
make sure the actual text value of the element does not contain any leading or trailing whitespace characters
is the entire text value of the element exactly equal to the value of your ValueID string? if not, maybe consider using the :has-text() Playwright pseudo-selector, e.g. await _page.ClickAsync($":has-text('{ValueID}')"); which not only is case-insensitive, but also matches on substrings
maybe try using the href attribute paired with a CSS contains instead, e.g. await _page.ClickAsync($"[attribute*={ValueID}]");
I have a method that prints labels from a Web Application in MVC5, for this I am using the Neodinamyc plugin
The problem is that this method delivers the encoded parameters, for the first printerName parameter I was able to decode it in the following way and I succeeded
But I think that the second parameter called location that is of integer type gives it to me as hexadecimal or at least I think so, since the error says: "can not be converted from int to string"
I'm currently testing with
ubicacion = Convert.ToInt32(ubicacion);
and it does not work for me, it still has the same value
Why do I get this hexadecimal type number when I pass an integer?
How can I convert this parameter to an integer? any help for me?
The value doesn't need to be converted, it's already an integer.
Your tooltip is just displaying it in hexadecimal. You can change this by right-clicking the tooltip and unselecting Hexadecimal Display
The screenshot sums up the problem:
I have no control over the retrieved value. It comes in with some funky format that I can't figure out and the parsing fails even though it looks totally normal. Typing the value in manually works just fine.
How can I "normalize" the retrieved value so Decimal.Parse does not fail?
For reference, here is the string that fails (copied and pasted):
"10.00"
First I would check your regional settings to eliminate anything as simple as a difference in expected decimal separator.
If that draws a blank then if the string 10.00 parses successfully then a string that looks like 10.00 but which fails to parse cannot actually be 10.00.
Inspect and determine the character code of each character of the string and confirm that it really is 10.00 and not some exotic Unicode that has the same appearance but which is actually different (which may also include characters which are not even visible when displayed).
You might have some kind of special character hidden in the string you are retrieving.
Try this:
Double.Parse(Regex.Replace(decimalValue, #"[^0-9.,]+", ""))
You might need to add using statement for System.Text.RegularExpressions
I would replace only the one problematic character, that is the safest option:
s = s.Replace("\u200E", "");
As Jeroen Mostert mentioned in a comment, there is a non-printed character in your decimalValue.
This is a similar question which should help you deal with that.
https://stackoverflow.com/a/15259355/7636764
Edit:
Using the the string output = new string(input.Where(c => char.IsLetter(c) || char.IsDigit(c)).ToArray()); part of the solution, but also include in || char.IsPunctuation(c) after IsDigit will get your desired result.
UPDATE May this post be helpful for coders using RichTextBoxes. The Match is correct for a normal string, I did not see this AND I did not see that "ä" transforms to "\e4r" in the richTextBox.Rtf! So the Match.Value is correct - human error.
A RegEx finds the correct text but Match.Value is wrong because it replaces the german "ä" with "\'e4"!
Let example_text = "Primär-ABC" and lets use the following code
String example_text = "<em>Primär-ABC</em>";
Regex em = new Regex(#"<em>[^<]*</em>" );
Match emMatch = em.Match(example_text); //Works!
Match emMatch = em.Match(richtextBox.RTF); //Fails!
while (emMatch.Success)
{
string matchValue = emMatch.Value;
Foo(matchValue) ...
}
then the emMatch.Value returns "Prim\'e4r-ABC" instead of "Primär-ABC".
The German ä transforms to \'e4!
Because I want to work with the exact string, i would need
emMatch.Value to be Primär-ABC - how do I achieve that?
In what context are you doing this?
string example_text = "<em>Ich bin ein Bärliner</em>";
Regex em = new Regex(#"<em>[^<]*</em>" );
Match emMatch = em.Match(example_text);
while (emMatch.Success)
{
Console.WriteLine(emMatch.Value);
emMatch = emMatch.NextMatch();
}
This outputs <em>Ich bin ein Bärliner</em> in my console
The problem probably isn't that you're getting the wrong value back, it's that you're getting a representation of the value that isn't displayed correctly. This can depend on a lot of things. Try writing the value to a text file using UTF8 encoding and see if it still is incorrect.
Edit: Right. The thing is that you are getting the text from a WinForms RichTextBox using the Rtf property. This will not return the text as is, but will return the RTF representation of the text. RTF is not plain text, it's a markup format to display rich text. If you open an RTF document in e.g. Notepad you will see that it has a lot of weird codes in it - including \'e4 for every 'ä' in your RTF document. If you would've used some markup (like bold text, color etc) in the RTF box, the .Rtf property would return that code as well, looking something like {\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf6\insrsid15946317\charrsid15946317 test}
So use the .Text property instead. It will return the actual plain text.
I am setting a value in the cookie using JavaScript and getting the contents of the cookie in the code behind.
But the problem is if I am storing the string with some special characters or whitespace characters, when I am retrieving the contents of the cookie the special symbols are getting converted into ASCII equivalent.
For example, if I want to store Adam - (SET) in cookie , its getting converted into Adam%20-%20%28SET%29 and getting stored and when I am retrieving it I get the same Adam%20-%20%28SET%29. But I wan tot get this Adam - (SET) in the code behind.
How I get this. Please help.
In C#
Use:
String decoded = HttpUtility.UrlDecode(EncodedString);
HttpUtility.UrlDecode() is the underlying function used by most of the other alternatives you can use in the .NET Framwework (see below).
You may want to specify an encoding, if necessary.
Or:
String decoded = Uri.UnescapeDataString(s);
See Uri.UnescapeDataString()'s documentation for some caveats.
In JavaScript
var decoded = decodeURIComponent(s);
Before jumping on using unescape as recommended in other questions, read decodeURIComponent vs unescape, what is wrong with unescape? . You may also want to read What is the difference between decodeURIComponent and decodeURI? .
You can use the unescape function in JS to do that.
var str = unescape('Adam%20-%20%28SET%29');
You are looking for HttpUtility.UrlDecode() (in the System.Web namespace, I think)
In javasrcipt you can use the built-in decodeURIComponent, but I suspect that the string encoding is happening when the value is sent to server so the C# answers are what you want.