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.
Related
I just came accross the below issue in a project of mine:
user clicks a button
a js function is called to check the
input of the form field and if accepted will submit the form to save_to_db.php in an
iframe.
in the iframe, save_to_db.php will save the form details to the db and calls another js function that updates the contents of html elements on the current page showing the latest status.
This used to work without any issues (and still does in most browsers).
But now in Chrome Mobile browser version 63.0.3239 somehow every link a user clicks after they clicked the button, will load to save_to_db.php (the form action of the button) instead of the link that is clicked.
Has anyone noticed this or similiar behaviour or does anyone know how to resolve this?
I'm trying to click on a button on a page that has a lot of JavaScript but no matter what I try, can't click it. Is there a way for me to click the button manually and get what I need to click?
I've tried inspecting elements and FirePath but those aren't giving me the correct class or id that I need to click
Edit: This is what I'm trying to accomplish, the below is from Selenium IDE firefox plugin
Command Target
open /logger/summary.ftl
clickAndWait link=System Admin
selectFrame sysadmin-content
click //div[#id='sysadminmenu__sysadminmenu_x-auto-29']/span[3]/span
click id=x-auto-178
You may try
http://www.seleniumhq.org/projects/ide/
This has a feature to find web element path
I'm wrestling with this problem now for well over a week. Our application uses jqGrid. I'm trying to do a search (in Selenium WebDriver 2.35 - it has to be that version for various reasons).
The jqGrid looks like:
JqGrid Search widget
When my Java-based Selenium WebDriver scripts change the search column to 'Name' (not an unreasonable task...) the search text field loses focus - it is circled in red in the attached image. However, doing a simple element.sendkeys("search") text does manage to populate the text field.
The problem is that when the automation clicks the 'Find' button, the data in the text field is not sent to the REST API backing it (eg. filter : {"column":"name", "operator":"cn", "data":""} )
When the response is received, the grid displays the same information. I believe the problem is that the element.sendKeys() method does not seem to generate a 'change' event.
I've tried the following to generate a DOM change event:
doing a click on some element within the Search widget.
tabbing to the the next field - element.sendKeys(Keys.Tab)
attempt to set the focus in the text box using Javascript/JQuery
JavascriptExecutor jse = (JavascriptExecutor) driver;
String script = "var searchtxt=document.evaluate('"+xpathQuery+"', document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue; "+
"$(searchtxt).focus()";
jse.executeScript(script);
- to no avail
attempt to trigger a 'change' event also through Javascript/Jquery to no avail
e.g. $(searchtxt).trigger('change')
I'm running out of ideas. Can anyone help?
Thanks,
Mark
I'm not use Selenium myself, but I'd like give you a tip. Searching Dialog hold internally the filter as string and update it every time inside of change handle. If the user fill the data interactively and then clicks on "Search" button then the change event should be send automatically. I develop free jqGrid fork of jqGrid and I includes the lines of code where I trigger change event once more on all input elements (on $(".input-elm") elements).
Thus I hope the problem should not exist in free jqGrid. If you have to use Guriddo jqGrid JS then I would recommend you to include explicit call of
$(".input-elm").change();
before Selenium will simulate click on "Search" button.
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"
I am developing my website using jQuery. For the Private Messaging feature, what I had right now is showing a ModalBox (dialog box). So, whenever user wanna check message, they will be displayed with a dialog box with the inbox shown. Now, inside that ModalBox, I have a "Compose" section where users can send message. My question is, when user submits the form, how we could retrieve those inputs without having to actually submit it? Because, I have tried it..., that when I do the submit(), it closed the ModalBox.
Any help would be appreciated.
Since you're using jQuery, see here
In case you're not familiar with AJAX, basically it allows you to send a request to the server (in this case, your submitted data), process the data on the server, and then receive any return back from your request, all without reloading the entire page.
This should alleviate the issue of the modal box closing (the page reloading upon submit, really.)
[edit]
See this article from here at StackOverflow on using the live event handler. This should take care of the issue of not getting the value from newly created DOM elements.
[/edit]