javascript auto fill form extension - javascript

I have a page and i wan't to fill it with my data. (Auto filling chrome extension).
I tried to work with vanilla javascript and JQuery, but they both don't work.
Here is my code:
$('#control_8 option[value=14401]').attr('selected', 'selected').trigger('change');
Here i use trigger(), so after a option is selected, in it subcategory it will load all items.
When i run this code in the console - it works. But if i run it from the chrome extension, it selects but trigger doesn't work.
SOS.

I guess there is a selector issue with your trigger function.
Split the code and try the trigger function in following way
$('#control_8 option[value=14401]').attr('selected', 'selected');
$('Your selector').trigger('change');

Related

Webpage doesn't refresh after input

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.

Trigger click with chrome console

I'm trying to trigger the click event on the Valid for and the Begin form fields in this Angular page using Chrome Console, I tried Javascript and jQuery using .click() or .trigger('click') with no luck so far. I'd expect when one of these fields is clicked the relevant dropdown would appear like it would if you manually click it using the mouse. Could someone help please?
https://www.eex-transparency.com/homepage/power/germany/production/usage/actual-unitwise-production-100-mw-
Thanks!

ASP.Net checkbox postback doesn't fire

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"

JavaScript/jQuery: Select specific option trigger file input

I'm searching for a way to have a HTML select box with arbitrary number of options and have the last option to "Upload a New Item" and trigger a file input element which I've hidden with css (display:none).
My problem is that I just can't get it to work and I've tried various of different functions and methods.
To test it I've tried the same thing with just a regular text link (a href) which works fine.
In addition I've also tried to test the change event on the select to trigger other events which works.
It is like it just won't accept a click trigger of an file input element.
You can see my different tests and approaches here: http://codepen.io/Mestika/pen/rvneK
edited
I'm on a Mac running Maverick in a Google Chrome
Cheers

localizing <asp:FileUpload>. IE problem

what i want to do is localize <asp:FileUpload> control. as far as i understand it is not possible, because input file is being rendered by a browser and there is no way to control it from the server.
so i do this: i create <asp:FileUpload>, make it transparent, create input text and input button and write
function browse() {
$('#fileupload').click();
}
on input button onclick event.
firefox and chrome does fine, IE8 - does not: it opens fileupload's "Browse..." dialog, writes it's value to input text (via $('#filepath').val($('#fileupload').val());), but when i start uploading, there is this problem: jQuery function before the Postback for FileUpload in ASP.NET
So my question is: is there any other (better?) way to override upload control (custom width, localized texts on button etc...), that works on every browser?
Thanks.
Have you tried uploadify so far?

Categories

Resources