I am writing a test that can login to a site. I am using C#, with Selenium.
1)there are two ID for password?! why would someone code it like this?
2)the ID contain number which is dynamic and keep changing each time the page is loaded.
the only different is with the name ID is:
id="txtPassword_155799780_I_CLND"
id="txtPassword_155799780_I"
I tried everything.
driver.FindElement(By.XPath(".//div[starts-with(#id,'txtPass') and contains(#text(),'I_CLND')]"));
driver.FindElement(By.XPath("//input[starts-with(#id,'txtPassword_')]")[2]);
<input class="dxeEditArea_DevEx dxeEditAreaSys dxh0" id="txtPassword_156029875_I_CLND" type="text" tabindex="0" saveddisplay="[object Object]">
<input class="dxeEditArea_DevEx dxeEditAreaSys dxh0" id="txtPassword_156029875_I" name="txtPassword_156029875" onfocus="ASPx.EGotFocus('txtPassword_156029875')" onblur="ASPx.ELostFocus('txtPassword_156029875')" onchange="ASPx.EValueChanged('txtPassword_156029875')" type="password" saveddisplay="[object Object]" savedspellcheck="[object Object]" spellcheck="false" style="display: none;">
Thanks
Your question is kind of all over the place. I would try and use something like the below xpath. I can't tell if you have two "password" elements displaying on the page or just one. Post the html and we can help you better.
//input[contains(#id, 'txtPassword')][1]
or
//input[contains(#id, 'txtPassword') and #type='text']
Related
Is there any way to disbale jquery validation on certain input fields inside a form? So that it won't bother me with the 'red text under my input' or whenever I submit my form. I'm searching for a while now but without any succes. I tried using formnovalidate="formnovalidate" from this questions but also without any succes.
Here's my cshtml input code:
<div class="form-group">
<label asp-for="preExposure" class="control-label"></label>
<input asp-for="preExposure" id="preExposureInput" class="form-control" type="text"/>
<span asp-validation-for="preExposure" class="text-danger"></span>
</div>
Although I posted as a comment that it was pretty similar to the linked question, the most important part of that answer is below:
Once you have the jquery validation turned on for the form with the .validate() you can still configure the rules for the individual element that you want, and remove all the rules.
$('#myfield').rules('remove'); // removes all rules for this field
I have something like this.
<input type="text">
I want enable/disable it based in certain variable value in server side.
I have tried this.
<input type="text" <%= DisableServiceInfo ? "disabled":"" %>/>
but not working.
I know this can be done.
<input type="text" disabled="<%= DisableServiceInfo ? "disabled":"invalid value" %>"/>
but this is not a valid mark-up. Because the only valid way to enable control is to remove disabled attribute.
I am not asking how value can be supplied based on variable but how attribute in injected
Please don't answer the ways to set it server side or by javascript. I just want to know if it is possible in this way?
Is this webforms? If you want to do this by the book, you can manually add an Id, and Runat="Server". Once you've done that, your control can be manipulated in your code-behind.
If your Id is ServiceInfo, you could do:
ServiceInfo.Attributes["disabled"] = "disabled";
I have a page where many postback clicks are there.
In this page many input elements there, which values are i am geting from server side using Request[]. like below
.aspx
<input id="txtRefTypeCtrlType_3" name="txtRefTypeCtrlType_3" lastvalue="4" CTRLtype="4" style="display: none;">
.cs
string strCTRLtype = Request["txtRefTypeCtrlType_3"];
now i have a scenario, where i need to get the CTRLtype attribute value.
Can we get the attribute value using Request[] or something else.
Please advise.
Thanks.
No, you can't get the attribute value on the server side because it isn't posted. The only real way of achieving this is to create a hidden field with the attribute value and use that:
<input type="hidden" name="ctrlType_3" value="4" />
Codebehind:
string attrValue = Request["ctrlType_3"];
I am trying to Implement the Google CSE in my site, I have formatted the look and feel of the Search box and result on google CSE site, now I want to do the following:
Have the search box on Master page so it shows up every where
Show results on a seperate page say "search.aspx", which is a child page of the Master
On Results page the Search box remain where it is in master page. and there is a div for it to show results.
I know we have following elements that can be used.
<gcse:search>
<gcse:searchbox> and <gcse:searchresults> A two-column layout
<gcse:searchbox-only> A standalone search box
<gcse:searchresults-only> A standalone block of search results.
But i suppose my requirement can only be met by using a combination of above, but not sure which one.
If any one has done this, can you please guide me what is the way to go.
a trick to that is to make a redirect to the search page placing the search on the url, eg something like:
You search everwhere (on master) for the word test, and your code if you are not on search.aspx is make a redirect to:
search.aspx?q=test
Now, inside the search.aspx, you read the query q and place it on the text box that google use to make search and that's all - ah, and one post back to google.
eg the code will looks like:
<form action="search.aspx" id="Form1">
<div>
<input type="hidden" name="cx" value="partner-pub-XXXXXXXXXX" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" size="46" value="<%=Server.HtmlEncode(Current.Request["q"]) %>" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
I just wanted to know that how can I get the ID of
<input type="radio" class="class1" id="radio1" />
with the help of CSS selectors in Selenium.
This is a more difficult and intriguing question than you might suppose. It is important to be aware that values for the HTML class attribute are not unique. Thus, it is quite possible (and in fact probable) that your HTML page may have multiple elements with the class set to "class1". So selecting strictly on the class will only work if your radio button is the first element on your web page with that class value. Working only with your example, a safer locator expression would be
selenium.GetAttribute("css=input.class1[type='radio']#id");
This matches only class1 elements that are radio buttons. It is much more specific--it correctly avoids prior elements that happen to also have the class1 value for the class attribute. But it is still not satisfactory--again it will match the first such element. You can improve further if, for example, you have more than one group of radio buttons. Say you wanted the first radio button in the second group from this code fragment...
<div id='group1'>
<input type="radio" class="class1" id="radio1" />
...
</div>
<div id='group2'>
<input type="radio" class="class1" id="radio1" />
...
</div>
... you could use a locator like this:
selenium.GetAttribute("css=#group2 .class1[type='radio']#id");
(Note that the space after '#group2' is important!)
However, the above is mostly to explain the problem rather than to provide a good answer, because the fundamental problem remains.
Most likely your code is really something like this, with multiple radio buttons all having the same type and same class, distinguishable only by position:
<input type="radio" class="class1" id="radio1" />
<input type="radio" class="class1" id="radio2" />
<input type="radio" class="class1" id="radio3" />
The only way to target one of these other than the first is by explicit indexing, but that requires you know the index a priori, e.g.:
selenium.GetAttribute("css=#group2 [type='radio']:nth-child(2)#id");
(For more on constructing CSS recipes for Selenium see my article and wallchart XPath, CSS, DOM and Selenium: The Rosetta Stone on Simple-Talk.com.)
I will give you an example:
selenium.GetAttribute("css=.class1#id");
Here is the link for the documentation http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.DefaultSelenium.GetAttribute.html