I'm making a change to an existing ASP.Net application via JS. I'm unable to look at nor edit the original ASP.Net code. What I am able to do is inject JS into the webpage. There are two radio buttons, and I want to change the default from one to the other, which I can do easily via JS. But when using the web app, when the other radio is chosen I can easily see there is a server post back happening and my JS code to toggle the checkbox does not fire this. Because of this, some server side function isn't getting ran to allow me to submit the form.
Just for reference here is my JS code that works fine, nothing to troubleshoot here. But even after inspecting the radio in Chrome I'm unable to see any event being fired. I might not fully understand how to inspect elements in chrome, any advice?
$(window).load(function() {
// this tests for the selected value
if ($("input[name*='radShippingAddressList']:checked").val() == "radSelectAddress") {
// this changes the radio button
$("input[name*='radShippingAddressList'][value='radAsBilling']").prop("checked", true);
}
});
You need to invoke the click method on the checkbox, in order for post-back to happen and the server side code to run. Try doing this instead of setting checked to true:
$("input[name*='radShippingAddressList'][value='radAsBilling']").click();
Auto postback on the control has to be enabled in order for prop changes to affect post back.
AutoPostBack="True"
Related
Currently im working on automating a website with selenium python. I have this problem whereby when i enter J590 into the target textbox MANUALLY, i will have to click anywhere on the website or pressing tab which than will refresh the website and an option will be available in a dropdown box. However, selenium does not seem to be refreshing the page for me.
I tried to use click() before and after sending J590 into the textbox,i also tried using send_keys(Keys.TAB) after sending J590 but none is working.
Here is the code i used to send inputs
driver.execute_script("document.getElementById('CustCd').value+="+ dumps(jcode))
Here is the code i tried after sending input
driver.find_element_by_xpath('//*[#id="Item"]/form/center/input[2]').click()
or
driver.find_element_by_xpath('//*[#id="CustCd"]').send_keys(Keys.TAB)
May i know why is selenium acting this way and is there a solution to it.
Seems to be the keyboard/onchange event are triggering when you tab out or click on another element in the page as you are using js to enter the data. So, you have to dispatch (simulate) the corresponding event.
Refer to this post to know the associated event(s) to the element.
Let's say if you want to trigger onchange event on an element, then you should get the element first.
ele = driver.find_element_by_xxxx(yyy)
then send the event to the element using the js as shown below.
driver.executeScript("arguments[0].dispatchEvent(new Event('change', {'bubbles': true,'cancelable': true}));",ele)
Make sure you returned the correct element. And change the event name accordingly.
I have a bootstrap switch checkbox which triggers an Ajax call. However, its functionality is pretty important and I need to ensure that it will work in any browser. I have a url that handle the request. What I need to know is how can I make the checkbox a "link" to this url if javascript is not enabled.
Note: I don't have a submit button.
Have the link in place on page render and remove it with javascript/replace it with the checkbox. This ensures that it's available to those without javascript.
I have a pop-up div contains a table.
Due to some issues, I need to make table rows clickable and can be catched by both js and .net server side .
Can or how can I use Request.form to solve this issue? since I've created functions for js part .
Or any other suggestions?
The reason why I want to fire sever side event, because I use JS to add option (item) to an asp:ddl in an updatepanel, it will cause error or lose the new option by doing a postback fired by other buttons.
Or any better solutions to this?
Regards
Check out this topic if you want to simulate a click event.
I have an OnBase e-Form that I'm building. There are three buttons on the form that all submit. OnBase does different things based on the name of the button used to submit the form. If the button has a name of OBBtn_CrossReference it opens another window with a cross referenced document. I need to programmatically 'click' that button.
I've read several posts about how to use JavaScript to submit a form, but none seem to accomplish my goal. I just need to POST and to have it appear to come from a button named OBBtn_CrossReference.
I don't need to submit any data. The way the page is currently set up, the entire page is already a form and since I don't want to break the functionality of the other form buttons it seems I must leave it that way.
UPDATE:
The suggestion below was tested as a call from the onload event in the body tag and since the button posts the page reloads and the call is made over and over again spawning unlimited child windows. I would appreciate a suggestion on how to get the button to only be clicked the first time the page is loaded and not on postback.
There's a click() method on links, buttons, checkboxes. For example , I submitted this comment by running document.getElementById('submit-button').click() from chrome's command line.
I know I am a little late to this post, but you can try and leverage a cookie to get this done:
if (document.cookie.indexOf('xref=true', 0) < 0) {
// Set the xRef cookie, so we do not fire it again for this form.
document.cookie = 'xref=true';
//alert(document.cookie);
document.getElementById("OBBtn_CrossReference").click();
}
else {
document.cookie = "xref=false";
//alert(document.cookie);
}
I tested this on the Thick and Thin clients in 10.0 and it worked fine.
The postings on this site are my own and don't necessarily represent my company's positions, strategies or opinions.
This is weird, but I've been using this method all over my code: I have dropdown lists that I populate client-side, using callbacks and because of this I'm unable to access their selected values from code behind and using a hidden field to store selected value in it. I had no problem retrieving the hidden field's value on postback, but all of a sudden it stopped working and is always blank, even when the value on client side is present.
Any thoughts?
P.S. I'm not setting or resetting hidden fields on postback.
Okay, if someone wonders what's wrong: it seems there's something related to jQuery.
The thing is that DropDownLists and the hidden field, along with the button that causes postback are inside a jQuery UI dialog that is initiated on page load without opening and appended to the form. Besides this dialog i'm initializin another one and also appending to the form, but for some reason the first appended dialog exibits the weird behavior when postback works, but hidden field does not retain the value. If i don't append the second dialog to the form, everything works as expected. Can't really tell what might appending the second dialog be doing that is causing this weird behavior.
P.S if i reverse the order in which those two dialog boxes are appended, it works just fine... Weird!
Using .NET?
When the values are added dynamically the backend has no clue. You need to use Request.Form to get the values posted back just like oldschool ASP days.