I want to remove specific value from a variable. For example, If I have a variable value as &MASTER&DYN,PHA/12345/12/56, I want to remove everything except the value &MASTER& i.e. value DYN,PHA/12345/12/56 to be removed. I tried with using .Remove() function, but was not successful.
why just not to assign needed value?
if (s.Contains("&MASTER&")) s = "&MASTER&";
Related
I am trying to get text from password field, as I need it to pass the test case.
Currently I am trying to do it with this
_passwordInput.SendKeys(user.Password);
Assert.Equals(_passwordInput.Text, user.Password);
However when it gets to the assert, it fails as it compares the user.Password value and returned value, which consists of only asterisks "*"
Tried it with GetAttrubute("value"), but got the same result
_passwordInput.SendKeys(user.Password);
Assert.Equals(_passwordInput.GetAttribute("value"), user.Password);
For now I changed the assert so that it would compare lengths of value
_passwordInput.SendKeys(user.Password);
Assert.Equals(_passwordInput.Text.Length, user.Password.Length);
Is there any way to get the text instead of asterisk, or should I just use the length?
Usually, you can get control value if it is at least visible in UI, and it also should be available in Inspector and Page source.
For Edit fields you can get value using:
_passwordInput.GetAttribute("Value.Value")
If the field value is hidden by *** you should first make it visible by pressing a special icon if it is available and then get the value.
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've run into a weird situation when looking up a value in a HashSet. It finds a match correctly when I pass in a hard-coded string, but not when using a variable whose contents are exactly the same as that hard-coded string.
This image and the debugging info at the bottom shows exactly the behavior I'm wondering about. Why does orgs.Contains(org) return false while orgs.Contains("Barr Family Practice") returns true? In this case, the contents of org are exactly "Barr Family Practice".
I'm using this line of code to insert a value from an array into a certain line, in a list of lines.
lineList[LineNumber].Insert(lineList[LineNumber].Count(), pArray[i]);
After debugging all the variables are correct, the pArray is passed in as a parameter and lineList is inherited from another class. I can't see why this wouldnt work, all the lines that are added are just empty?
This is because .NET strings are immutable; string.Insert returns a new string, rather than modifying an existing one. If you need to modify the string, add an assignment, like this:
lineList[LineNumber] = lineList[LineNumber]
.Insert(lineList[LineNumber].Count(), pArray[i]);
This should be equivalent to
lineList[LineNumber] += pArray[i];
I donĀ“t know how to resolve a situation i have. I have a regular expression that validate a textbox input, what i need is to prevent or remove characters that not mach the regular expresion while the user is typing.
my regular expression is:
^[A-Z0-9]+(\.[A-Z0-9]+|[A-Z0-9]*)*$.
it allows letters,numbers, and dots (but no more than one consecutive), but it can be change without notificacion (by system configuration)
Any idea how to solve it?
Upd: it`s a winforms application
You could keep a local variable that stores the value of the textbox. On each keypress, check whether the key matches the regex. If so, add the character to the local variable, and set the textbox's text field to the variable. Otherwise set the textbox to the current value of the local variable, thus overwriting the bad input.
Use Custom validator with this regex.