These spaces are not added by me on HTML SIDE and i cannot edit HTML
I want to know what should my comparison string?
I am using watin to automate website testing process but I am unable to encounter only one button.Every other works
watin searches content by name /values /id and many more and works fine but when i see the value of the submit button that i need to be clicked it has some breaks &nsbp so i think they are playing some role
Here is the html:
<span class='button'><input type="submit" value=" Login " /></span>
<span class='button'><input type="button" value=" Back " onclick="history.back(-1)" /></span>
and here is the code to search
browser.Button(WatiN.Core.Find.ByValue(" Login ")).Click();
what can be done??
-- Suggestion -- (i.e. too big for a comment)
You shouldn't use to add spaces to the submit button. Rather, you should use CSS to style the button to your liking. So you would have something like:
input[type=button] {
padding:10px;
min-width: 150px;
}
By the same token, this could eliminate any of the issues you're having with selecting the button. It could be an issue of encodings breaking with watin and as a result, doing this with CSS will make debugging the issue much cleaner and much easier.
Edit:
Have you tried searching by ID as opposed to by value? ID's are supposed to be unique on a page, so if it doesn't find it by those means, then that's one issue that can be rules out. It could also be the fact that you're searching for a button. A <button> is not the same as a <input type="button">.
Edit 2: Even though the issue was due to encodings breaking, I still recommend you reset that button to reset the text (removing all the non breaking spaces) and attach an id/name to it. The reason being for internationalization purposes - and if for some reason you modify the size of the button in the designer, or i18n the app and the text is different, your test will break.
You shouldn't use entities with WatiN.
This code will work, but you have to use real non-breaking space character:
browser.Button(
WatiN.Core.Find.ByValue(
" Login ")).Click();
This is probably inconvenient, but you could use (after adding reference to System.Web) HttpUtility class:
browser.Button(
WatiN.Core.Find.ByValue(
System.Web.HttpUtility.HtmlDecode(
" Login "))).Click();
But, if I were you, I would just go with Regex:
browser.Button(
WatiN.Core.Find.ByValue(
new Regex(#"^\s*Login\s*$"))).Click();
or even new Regex("Login").
Interesting thing: If you ever will have to Find.ByText you don't have to bother so much, and you can use regular space (ie. not exactly non-breaking space). That's because native IE IHTMLElement::getAttribute (http://msdn.microsoft.com/en-us/library/aa752280(VS.85).aspx) converts from innertext attribute to regular spaces, but from value, id etc. it doesn't ( are converted to real non-breaking spaces - 0xA0)
Wow, you really like spaces! I would remove those and use padding/margins like html was designed to be used. Then you wont need all those spaces and you can assign a proper value to your button which watiN will recognize.
I think it is because the in the HTML source is actually an escaped version of the special character that represents a none breaking space. So in you C# source, you'll probably need that character instead of the html entity code. I think you can find the code of that character by using this button to submit a GET form. It will show the escaped character code in the url.
Of course it is better not to put the spaces in there at all. You should give the button a padding using CSS instead.
Related
that's my first question, i hope i'm doing everything correctly.
Anyway, i have a weird issue. I basically have this HTML input which i want to fill with WatiN :
<input name="edit[id]" class="form-text required" id="edit-id" type="text" size="60" maxlength="64" value="">
That's my code in C# :
IE ie = new IE();
ie.GoTo(urlhere, just too long);
ie.TextField(Find.ByName("edit[id]")).TypeText("Text");
It's not working and it returns this exception :
Ulteriori informazioni: Could not find INPUT (hidden) or INPUT (password) or INPUT (text) or INPUT (textarea) or TEXTAREA element tag matching criteria: Attribute 'name' equals 'edit[id]' at about:blank
I'm not sure why it gives "at about:blank" honestly. I tried with a random google page and the code it's working. If i put a random name instead of the correct one, it gives me the same exception but with the correct url instead of "about:blank".
Note : I'm trying to fill a form.
Thanks for your help!
Not sure what web page are you using but from the information you posted it looks like that form might be "somewhere else" (another div, frame, etc.) To be able to find the EXACT entry you should press F12 (IE) or CTRL+SHIFT+I (Chrome) and traverse the HTML web page to find the exact portion were the input lies and you will find the exact spot.
The code you posted is perfectly fine, there's nothing else you need to do to make it work. If you need more help, posting the webpage you are trying to use will go a long way (if possible, of course).
I have a webpage with 2 search fields (top and bottom) and some text in-between them and I want to send a query to the bottom field. Both fields are identical (same code).
I tried storing the bottom one in a variable and use that variable to send the keys, but somehow it always sends the text to the first one.
var bottomSearch = _WebDriver.FindElements(By.Id("inputBox"))[1];
Assert.IsTrue(bottomSearch.Displayed);
bottomSearch.Clear();
bottomSearch.Click();
bottomSearch.SendKeys("test");
bottomSearch.SendKeys(Keys.Enter);
So: Clear() works and properly deletes any text already present in the bottom search, Click() also works, SendKeys sends text to the top searchbox and SendKeys(Keys.Enter) goes back to the bottom one and presses Enter from there.
I use the firefox driver and also tried selecting the element by CssSelectors or other identifiers but did not work.
Any help or ideas are most appreciated!
Thank you!
Here is the code for the search fields:
<div class="searchbox-input">
<input id="inputBox" class="querybox" type="text" placeholder="Entrer le terme recherché" name="inputBox" value="test">
</div>
OK, so after 2 days of trial and error I asked the website's devs to change the id of the bottomSearch and now everything works well.
After all these tries I'm tempted to suspect a bug in the driver or the SendKeys() method, but since I failed to found any reference to back this up and I successfully dealt with same ID fields before, maybe it's just something in the website's implementation or mine.
So in conclusion, follow the best practice advices and this should never happen :)
In my signup form, I'm using asp.net unobtrusive validation to check if a username exists. My JsonResult method returns the following if a clash is found:
This is already in use. How about \u003cstrong\u003efoo123\u003c/strong\u003e?
I use Microsoft's unobtrusive validation to display this in my view:
#Html.ValidationMessageFor(m => m.Username)
which causes it to appear as follows in the page source:
This is already in use. How about
<strong>foo123</strong>
?
As you can see, the text is split over three lines. This is not a problem in Firefox, but in Chrome these new lines are causing the displayed text to break in a similar manner to <br />. I believe the encoding is to blame for this - can anyone explain why? Is there any solution to this issue?
Thank you in advance.
Without having tried it, you could try to replace newlines in the string with... nothing?
#Html.ValidationMessageFor(m => m.Username).ToString().Replace(Environment.NewLine, "");
Feels really weird that would be the problem though since it's just in Chrome, double-check CSS rules. Or just surround the validation message in a p-tag?
If they are displayed with line breaks on the actual page, then first thing I would do is inspect <strong/> tag and see if there is any CSS that defines it as display:block; or overrides white-space property.
If you are concerned about output of the DOM explorer... That's just how Chrome displays DOM trees. These three lines are each individual nodes (2 text nodes and one element node), so they are treated as equal. If you inspect the first paragraph of my answer, you will see the same thing.
try tweaking with css.
\u003cdiv\u003e
This is already in use. How about \u003cstrong\u003efoo123\u003c/strong\u003e?
\u003c/div\u003e?
I think this is due the some padding issue. Upload the generated Html code of the page.
I have an issue with the following text display:
<asp:RegularExpressionValidator ID="Password_RegularExpValidate" runat="server"
Text="TEST!"
Display="Dynamic"
BorderStyle="None"
ControlToValidate="txtNewPass"
ValidationExpression="(?=^.{8,255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*"
meta:resourcekey="Password_RegularExpValidateResource1" /></td>
The pattern by itself is:
(?=^.{8,255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*
The text initially had some stuff in it as the ValidationExpression was different. I've changed the regex expression and that works, but when I write something in Text= it doesn't update on the page. I've restarted IIS, cleard the IE chache... everything I could think of. The old text keeps appearings (ie. "TEST!" doesn't show up when the validation fails as it should).
Any help would be appreciated.
Edit:
The code for txtnewpass:
<asp:TextBox ID="txtNewPass" runat="server"
TextMode="Password"
MaxLength="256"
meta:resourcekey="txtNewPassResource1"></asp:TextBox>
Also, it's worth noting that I can remove an entire table from a page that it disappears when I reload the page. But when I change text values from controls or anything that runat="server" and the page doesn't seem to update with the text....
And the code behind doesn't edit the field that displays, the validator validates the text in the textbox and uses that value later.
Edit 2: Same thing happening with -
<asp:Label ID="Label1" runat="server"
Text="Change Password!!!!!"
meta:resourcekey="Label1Resource1"></asp:Label></td>
I've added the exclamation marks (!!!!!) and that's not showing up when I refresh the page either.....
Edit 3: As I've noted in one of the comments, if I delete a table from the page and reload the page, that table disappears, so I know the page is reloading properly. The runat="Server" property, does that work a certain way where it caches text or something? I'm out of ideas....
Like Kirill said, use ErrorMessage instead of Text.
But the main problem is, I think, your localization, which is handled through the meta:resourcekey tag and resources.
Here is a good explanation:
ASP.NET meta:resourcekey
If you set automatically or manually the resource localization file and change something afterwards, for example a Label Text property, then you need to do it in the resource file too. Because there should be your initial value, which is loaded at runtime.
There are a lot of possibilities for the source of the problem, and there's not really enough info to tell which one it is. It sounds to me like one of these:
1) An external issue with your application or page (perhaps your ViewState isn't being set up properly, or the validation is getting called before PostBack).
2) You should be using RegularExpressionValidator.ErrorMessage instead of Text, as Kirill suggested. You said that you had changed that, but I wonder if you've reloaded the page (you could try rebuilding the app or something if it's getting cached somehow).
3) Your regex might not be doing what you think it is. The pattern is extremely long, and it seems strangely written. Adding some whitespace, we find that it looks like this:
(?=^.{8,255}$)
(
(?=.*\d)(?=.*[A-Z])(?=.*[a-z])
|
(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])
|
(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])
|
(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9])
)^.*
Which simplifies down to something like:
^(
(?=.*[A-Z])(?=.*[\W_])(?=.*[a-z\d])
|
(?=.*[a-z])(?=.*\d)(?=.*([A-Z\W_]))
).{8,255}$
Is this what you intended? I see where you're going with the password rules, but it may be easier to just simplify them and require one capital, one lowercase, one number, and one special character. You could also try to get validation working with a simpler regex pattern, and then add complexity once everything else is working.
Try to use RegularExpressionValidator.ErrorMessage instead of Text.
Try restarting VS. Sometimes incredible bugs disappear after that.
Try removing and regenerating your ..aspx.designer.cs file (to
regenerate right click the aspx/ascx file and choose "convert to web
application").
Agree with others, you should indeed check your resource file.
I am using default asp.net ToolTip property, the text is
This is Going to be a long text
Thats why we decided to split it.
but using <br/> to split the line doesn't work, it renders as a text, and I want it to break the line instead.
Here is my code:
Label lblActionText = new Label();
lblActionText.Text = "Helloooo Phaltu";
lblActionText.Style.Add("cursor", "pointer");
lblActionText.ToolTip =
"This is Going to be a long text"
+ "<br/>"
+ "Thats why we decided to split it.";
I've not tried this but would "System.Environment.NewLine" not do the job instead of the BR tag?
You can use this to insert a line break inside a ToolTip.
lblActionText.ToolTip = " First text " + Environment.NewLine + " second text ";
Use the line break character entity (
). It is easy to implement but the only problem is that this will work in IE & Chrome but not Firefox.
lblActionText.ToolTip = "This is Going to be a long text
Thats why we decided to split it.";
See jsFiddle: http://jsfiddle.net/jafLf/
You are passing a string value to a Tooltip, and that's why the HTML element <br /> is not working.
However you can try this ASP.Net AJAX TooltipExtender
This works only on IE but other browsers are not!!
If you want to have a customize tooltip then seach for jQuery tooltips to have a formatted tooltip
You can do this with adding a table in the tooltip :)
Example: ASP forum
The ASP.NET ToolTip property corresponds to the HTML title attribute.
In IE and Chrome you can simply do:
<span title="multiline
tool
tip">Mouseover me!</span>
However, that won't work in Firefox as it actually follows the W3C guidelines for CDATA.
CDATA is a sequence of characters from
the document character set and may
include character entities. User
agents should interpret attribute
values as follows:
Replace character entities with characters,
Ignore line feeds,
Replace each carriage return or tab with a single space.
Your best bet (considering you also want to change the colour) would be to go with a jQuery solution such as QTip which gives you all the customisation you want and more..
You cannot change the color of a tooltip with the default title attribute. For that the only way is to use a javascript generated tooltip.
There are plenty of plugins for jQuery such as:
Dynamic tooltip
Popup Bubble
jQuery Horizontal Tooltips
Coda Popup Bubble
Awesomeness
TipTip
(mb)Tooltip
vTip
jGrowl
jQuery Ajax Tooltip
Digg-style post sharing tool with jQuery
Input Floating Hint Box
Simpletip
qTip
Orbital Tooltip
And many more, check them here: Stylish jQuery Tooltip Plugins Webdesign
You can also just create your own using javascript. Add a mouseover event on the element then show a hidden div over the element with whichever html elements you want, in whichever color you need.
It is also more safe to use a javascript approach for cross-browser compatibility.