jQuery syntax while using master Page - asp.net

I am using master page where i need to move value of one listbox to the other with the help of jQuery I tried many ways but wasn't able to hit the nail.
The methods I tried are as follows:
$("[id$='ModuleMasterListBox option:[#selected]']").appendTo($("[id$='ModuleSelectListBox']"));
$("[id$='ModuleMasterListBox option:#selected]'").appendTo($("[id$='ModuleSelectListBox']"));
var module = $("[id$='ModuleMasterListBox']").val();
module.appendTo($("[id$='ModuleSelectListBox']"));
These are the methods I tried which failed - please help me out....

You should be able to do it like this:
$("[id$='ModuleMasterListBox'] :selected").appendTo("[id$='ModuleSelectListBox']");
From your markup and the # sign it looks like you're using an outdated version of jQuery, you may want to consider upgrading. In the above we're using the attribute-ends-with selector to get the <select> the using :selected to grab the selected <option> before moving it.
Keep in mind since it looks like you're using ASP.Net this will by default throw validation errors on the server-side, you'll have to disable page validation for it to allow items it didn't bind.

Related

how to add a conditional statement into .aspx page controlled by angular js

working with asp page and I need to change "true-false" statement on table. But I couldn't figure out how to add "string" instead of boolen data on asp page. That's asp code block, which I need to change it.
<tr data-ng-repeat=" ticket in ticketList">
<td>{{ticket.UserId}}</td>
<td>{{ticket.State}}</td>
<td>
I tried to do that
<td>{{<%# ((bool)Eval("ticket.State") != false) ? "Tested" : "NotYet" %>}}</td>
but, It doesn't work. how can I put a conditional statement into that cod block. Thanks for any advice.
Since this is angluar JS app, you can not use <%# Eval .. %> thing here. You might have noticed that you are using loop with ticket in ticketList in data-ng-repeat.Point is you can not apply server side implementation for rendering there. You need to do in angularjs way. Following are some examples to do it.
If you have angularjs version >= 1.1.5, then following way would work.
<td>{{ticket.State === "false" ? "Tested" : "NotYet"}}</td>
For lower version, this will be helpful - inline conditionals in angular.js
Or there are other directives like ng-show, ng-hide, ng-switch, you can try those too!

Nightwatch Cannot Find/Click on Dropdown Option

I'm a backpacker and a programmer, trying to use the second skill to find openings in a full campsite. Rather than crawling fro scratch, I'm using the end-to-end testing framework nightwatch.js to navigate for me.
I've hit a roadblock, because nightwatch is having difficulty finding a specific element using css selectors.
Here are the elements and page:
Here is my test code:
Previous Attempts
My test code will click on the selection box with #permitTypeId. It will see that #permitTypeId option is visible. It will not see or click on any of the options when more specific values are specified. The five .click()'s are all css selectors I've already tried. None of the options are set to display:hidden or display:none. I have also tried all of the above without the .waitForElementToBeVisible() just in-case the waiting causes the dropdown to hide.
I've successfully clicked options from different dropdown menus on this website without any problem. Just this one is causing a headache.
The tests are running with the most current Selenium server and Firefox on Mac Yosemite.
tl;dr
Nightwatch.js/Selenium won't click on something from a dropdown menu.
The Path...
Cory got me thinking about jQuery and native DOM manipulation. Tried going that route and was successful selecting the correct option using Selenium's .execute() function:
.execute('document.getElementById("permitTypeId").options[1].selected=true')
However, it was not triggering the onchange event.
Saw this post which made me start thinking about using key-strokes and this one which suggested using arrow-keys to navigate down a <select> element to the option, then hitting enter.
...to the Solution
.click('select[id=permitTypeId]')
.keys(['\uE015', '\uE006'])
I've found that this is an issue with Firefox. Chrome and PhantomJS operate well clicking <option> tags.
you should be able to click like this way
browser.click('select[id="permitTypeId"] option[value="1451140610"]')
Additionally I was able to add a .click event for the specific option once I did a .click for the select. see my example below:
.click('select[name="timezone"]')
.pause(1000)
.click('option[value="America/Chicago"]') //selects the option but doesn't click
.pause(5000)
.keys(['\uE006']) //hits the enter key.
another solution:
.click('select[id="permitTypeId"]')
.waitForElementVisible("option[value='1451140610']")
.click("option[value='1451140610']")
Very simple way is to use .setValue('#element', 'value of option')

setting Style property of a WebControl From Code Behind

recently I found in one of my older projects (asp.net 4.0)
that I've been using this code
to set display Style-property To none
DDL_ChosenEmpl.Attributes.Add("style", "display:none");
lately I was using
DDL_ChosenEmpl.Style.Add("display", "none");
i would like to know
in any case such as - property already exist whether it's with different value or not , will any of them should be avoided ?
what are the main differences between both methods ?
Both does the same functionality as you have done. The thing is, in "Attributes" collection, you have a control's other attributes like "click", "dblclick", etc. You can use either way. I believe Microsoft has given the later part for user's convinience to make coding easy.

How to use seleniumRC in Junit framework on dynamically changing elementids

I am trying to automate a work flow process .In this,I need to click on a link positioned in any of the rows of table.Thing is all links available in all rows have same element ID and in the source code I have a java script like " ("Element ID" # Onclick..java script****:).....SO here after clicking it is connecting one form to another form by inputting some value in java script code and also one value in java script dynamically changes.How do I click on that link now?Is there any solution using xpath or so...to exactly click on that link based on CSS classID or so...Please help me out..Main problem is...all links in rows have same element ID and dynamically changing java script .
I am trying to use selenium.focus() and selenium.clickAndwait().But these are helpless.as it is not able to identify link ID only.
The best way to do this would be with xpath.
Something like //*[#onclick='javascript'] will work but this can make the tests extremely flaky because if the inline javascript changes or if its removed in preference of addEventListener to the element.
something like //*[#class='cssClass'] will work. I think that you will need to speak to the developers and ask them to help make it more testable.

Multiple reCAPTCHAs in one ASP.Net page

It is possible to add multiple reCAPTCHAS in one form? I tried doing so, even giving the multiple reCAPTCHAS different IDs, but when I load the page in the browser, only one of them is shown.
Is this by design? I need the two reCAPTCHAS because one is for Login, and the other one is for the Register form, which will be shown on the same page.
Thanks!
WT
Only one Cpatcha is supported in a page at any time. What you can do is use AJAX and lod captcha after the form is loaded.
This might of some help.
After a quick google search, it appears that it's not currently possible. One suggestion I saw was to pop up a modal recaptcha just as the user submits the form. ondemandcaptcha for Ruby.
I was initially lead by this thread to believe there is no simple answer, but after digging through the Recaptcha ajax library I can tell you this isn't true! TLDR, working jsfiddle: http://jsfiddle.net/Vanit/Qu6kn/
It's possible to overwrite the Recaptcha callbacks to do whatever you want with the challenge. You don't even need a proxy div because with the overwrites the DOM code won't execute. Call Recaptcha.reload() whenever you want to trigger the callbacks again.
function doSomething(challenge){
$(':input[name=recaptcha_challenge_field]').val(challenge);
$('img.recaptcha').attr('src', '//www.google.com/recaptcha/api/image?c='+challenge);
}
//Called on Recaptcha.reload()
Recaptcha.finish_reload = function(challenge,b,c){
doSomething(challenge);
}
//Called on page load
Recaptcha.challenge_callback = function(){
doSomething(RecaptchaState.challenge)
}
Recaptcha.create("YOUR_PUBLIC_KEY");
It is now possible to do this easily with explicit recaptcha creation. See my answer here:
How do I show multiple recaptchas on a single page?
It's not too difficult to load each Recaptcha only when needed using the Recaptcha AJAX API, see my post here:
How do I show multiple recaptchas on a single page?
the captcha has an img element #recaptcha_challenge_image element , so after you set the recaptcha in one div say "regCaptch",get that img src attr
,set your other captcha div html to the old one html and then set the #recaptcha_challenge_image src to the src you get , here is a working example
var reCaptcha_src = $('#recaptcha_challenge_image').attr('src');
$('#texo').html($('#regCaptch').html());
$('#recaptcha_challenge_image').attr('src',reCaptcha_src);

Resources