Why TWebbrowser IHTMLElement.click fails while mouse click succeeds - javascript

I'm trying to auto-fill a web page. Filling input elements and navigating with buttons works fine. Just the final "Save" button fails when programmatically clicking on it, while clicking with the mouse succeeds. The Save button appears to contain some Javascript. In the document it looks like this:
<a title="Enregistrer / Save"
class="btn--icon icon-save ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
id="_save"
onclick="
$('#overlayLoading').dialog('open');
$('#form_model').attr('action', 'https://<some url>');
$('#form_model').submit();"
abp="1909">
<span
class="ui-button-text"
abp="1910">Enregistrer<br
abp="1911">
<span
lang="en"
abp="1912">Save
</span>
</span>
</a>
I tried 3 different approaches:
First approach:
Search for IHTMLelement with id "_save" and do .click()
Navigate() to the URL that is embedded in the element
Executing the JavaScript like this
var
Script: string;
DocPtr: IHTMLDocument2;
WinPtr: IHTMLWindow2;
Script :=
'$(''#overlayLoading'').dialog(''open'');'+
'$(''#form_model'').attr(''action'', ''https://<some url>'');'
'$(''#form_model'').submit();';
if Supports(WB.Document, IHTMLDocument2, DocPtr) and
Supports(DocPtr.parentWindow, IHTMLWindow2, WinPtr) then
WinPtr.execScript(Script, 'javascript');
All 3 methods do seem to work, but the web server returns an error page. When I instead click on the button presented in the TWebBrowser with the mouse, the web server returns success.
What is the physical click doing differently from the programmic click?

Related

How to add a new webpage to ASP.NET MVC

Right now I am making a MVC that has a default page that loads up. From this page, the user can press a button to go to the next page. So far, I have made the first page work and a button that goes to a specified URL for the second page. The only issue I am having is making the view that I want to correspond to the second page have the correct URL.
Here is the code for my button link to the next URL
<input type="button" value="Create" onclick="location.href='#Url.Action("IndexA", "HomeController")'" />
I guess my question is how do I make my view have the specified URL that I want so it can be accessed?
I used something like this in my own project.
#if (Request.UrlReferrer != null && Request.UrlReferrer.Host == Request.Url.Host)
{
<a href="#Request.UrlReferrer" class="dbtn btn-11">
<i class="fa fa-undo"></i>
#Resources._Action_Back
</a>
}
only came from within the domain that was published I said let the button appear.
there is something like add controller in default settings controller name + controller. So just write the name there.
I had to put "home" in the URL.Action instead of "HomeController"
Please see this photo.
https://ibb.co/4SS5nYh
You add a new controller and a new view for that new page (also a model). I have called mine Test.
Then in the button. you call them with url action.
<input type="button" value="Create" onclick="location.href='#Url.Action("Index", "Test")'" />

Javascript box not being triggered in selenium

I'm currently trying to automate part of our web application, mainly a form of #mentioning similar to facebook. In the front end when a user types # into a text input the API calls the list of users and displays them in a box that appears. This element is currently at the end of the DOM and not visible until the javascript triggers when the # is typed.
My selenium code uses send_keys to populate the #namehere but the user window element doesn't appear, even if i do it manually while the browser is opened via selenium
I've tried using the upkey event from Action Chains, injecting javascript to trigger the event, clicking back onto the text input to make sure its focused but nothing works. This happens in both chrome and firefox
Literally searched everywhere, any ideas?
Feature step:
And i create a post titled "#James"
implementation:
#when('i create a post titled "([^"]*)"')
def step_impl(context, text):
page = ActivityStreamPage.NewPost(context)
page.post_input.click()
page.post_input.send_keys(text)
element:
'post_input': (By.CLASS_NAME, "js-post-textarea")
web element:
<div class="js-post-textarea js-edit-content editor__editable"
contenteditable="true" autocomplete="off" autocorrect="off"
autocapitalize="off" placeholder="Write a post or #mention to notify
someone"><span class="atwho-query">#</span><br></div>
user box:
<div class="atwho-view" id="at-view-64" style="display: none; top:
135px; left: 440px;">
<ul class="atwho-view-ul">
<li class="mention__item cur">
<p class="mention__notice">
<span>#Group</span>
"Notify everyone in this Group."
</p>
</li>
</ul>
</div>
after a lot of debugging, seems that the AJAX call was being refused due to permissions. a defect with the application rather than selenium.

Clicking a JavaScript link on website

I am trying through VBA to generate automatically a report from my bank's website.
I managed to reach the website and plug in my user id and password without any problem. I've reached the page where I can normally generate the report.
Now I have to simulate a click on the link... But I can't manage to do it.
Here is a screenshot of the website, with the HTML code of the link I have to click on to generate the report (Summary Report Copy).
Here is the HTML code of the link I need to click on:
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false" class="">Summary Report Copy</a>
I've tried this line of VBA code, but doesn't work:
IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestatus").FireEvent "onclick"
How can I click on this "Summary Report Copy" thanks to VBA?
Here is the complete HTML code of the part of the webpage where the link is located. Maybe I am not using the right ID?
<td width="290px">
<span id="irCustomStepOne:headerDataTableId:23:reportNmGrp">
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false">Summary Report Copy</a>
<a id="irCustomStepOne:headerDataTableId:23:reportnamePrint" href="#" style="float:left;display:none;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if (!onReportLink(\'23\')) return false;','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamePrint\':\'irCustomStepOne:headerDataTableId:23:reportnamePrint\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Print\'},\'_blank\')');return false">Summary Report Copy</a>
<span id="irCustomStepOne:headerDataTableId:23:rpId" style="float:left;display:none;">3368127</span>
</span>
</td>
This always worked for me. Try it please:
For each lnk in IE.Document.getElementByTagName("a")
If lnk.ID = "irCustomStepOne:headerDataTableId:23:reportnamestat‌​us" Then
lnk.Click
Exit For
Next
You might have to wait for the page to be fully loaded. Something like
Do: VBA.DoEvents: Loop While IE.Busy ' wait for the page to load
Dim el 'As IHTMLElement
Set el = IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestat‌​us")
If el Is Nothing Then el = IE.Document.querySelector("a[title='Summary Report Copy']")
If el Is Nothing Then MsgBox("Link not found!") : Exit Sub
el.click
Do: VBA.DoEvents: Loop While IE.Busy ' wait for next page to load

Javascript function inside ui:repeat to show/hide contact formular not working

I have a facelet that shall dynamically list teachers loaded from database with name, profile picture etc. etc. Every listed teacher has its own contact formular, which gets hidden after pageload, and a button "get in touch" which, onclick, shall open the contact formular below and hide the button "get in touch". The formular has some text fields and a submit button "send request". After clicking "send request" I want to call a backing bean method which saves the request in the database, and, with javascript, hides again the contact formular and shows the "get in touch" button instead.
Here is the page listing the teachers:
<ui:composition template="/WEB-INF/templates/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<script type="text/javascript">
$(document).ready(function () {
$(".request_form").hide();
});
</script>
<ui:repeat id="teachers" var="teacher" value="#{teachersController.teachers}" varStatus="it">
profile picture, infos, etc.
<p:button id="btn_open_request_form"
value="get in touch"
onclick="$('#teachers:#{it.index}:request_form').show(300); $(this).hide(); return false;"/>
<h:form class="request_form" id="request_form" prependId="false">
Text inputs for email, message...
<p:button value="#{msg['cancel']}"
onclick="$('#teachers:#{it.index}:request_form').hide(300); $('#teachers:#{it.index}:btn_open_request_form').show(); return false;"/>
<p:commandButton value="send request"
process="#form"
update="#form"
action="#{teachersController.sendRequest(teacher.id)}"
oncomplete="$('#teachers:#{it.index}:request_form').hide(300); $('#btn_open_request_form_#{it.index}').show();"
/>
</h:form>
<h:messages></h:messages>
<br/>
</ui:repeat>
</ui:define>
</ui:composition>
In a first attempt I was using c:forEach instead of ui:repeat to iterate over the teachers. The showing/hiding of the contact formular and buttons with jQuery was working perfectly, but the action method of p:commandButton could not be called and no request was sent, so I switched to ui:repeat.
Now, the requests are saved to the database, but the hiding/showing with Javascript doesn't work anymore. The formulars get hidden by pageload as expected. But then, when clicking on "get in touch", the button itself gets hidden, as I want, but no formular is shown.
It took me a while to figure out how jsf generates all the id's but I got it right in the end by checking the generated html. Here is the generated html of the button:
<button id="teachers:1:btn_open_request_form"
name="teachers:1:btn_open_request_form"
type="button"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
onclick="$('#teachers:1:request_form').show(300); $(this).hide(); return false;;window.open('/lehrerverzeichnis/faces/requests/teachers.xhtml','_self')">
here the one of the form:
<form id="teachers:1:request_form"
name="teachers:1:request_form"
method="post"
class="request_form" ...>
What am I getting wrong? Before, when using c:forEach, it worked well (with different id's of course). But the selector in jQuery function matches the form id, why isn't it shown after clicking the button? The button itself gets hidden by the command afterwards, so the onclick function gets called for sure.
It seems to me that combining Javascript and JSF is not a good idea. What else could I do instead?
Thank you very much in advance..
SOLVED It was just a stupid mistake. The semicolon in the jQuery Selector needs to be escaped. In the created html source, $('#some:id') would need to be $('#some\:id'). To have two backslashes remaining they must be escaped as well in the facelet. So in the .xhtml file there must be written $('#some\\\:id'), so 4 backslashes before the colon are necessary that 2 survive in the created html.
Thats why I prefer Java, it would at least have told me where the problem is.. :D

How to stop scroll up for <button dojoType="dijit.form.Button" type="submit"/> in IE11

I am currently working in a web application which has dojo in client side.Now for browser IE11 I am facing a scrolling issue for the following component
<button dojoType="dijit.form.Button" type="submit" name="favouriteList" value="favoriteList" onclick="buttonfix(this);"/>
The Problem I am facing is in some pages where scrolling is coming,when user scrolls down to button of the page(since the buttons are at button of the page)and clicks on the button,no action is fired and the page scrolls up to the top..To be noted this is happening only on first click on the button.Now if user again scrolls to the bottom and places the cursor on button and clicks it then the corresponding action is getting fired.
From my First inspection I got the impression that dojo is probably the cause of this problem.Sop,I tried the following:
I removed the dojoType="dijit.form.Button" attribute.It resolved the issue.But unfortunately It is not acceptable since in our project we need to keep intact dojo.Our dojo version is 2.1.
The entire generated html for a particular button of my project is below:
<button name="favouriteList" tabindex="0" class="dijitReset dijitStretch dijitButtonContents" id="dijit_form_Button_9" role="button" aria-labelledby="dijit_form_Button_9_label" type="submit" waistate="labelledby-dijit_form_Button_9_label" wairole="button" dojoattachpoint="titleNode,focusNode" value="favouriteList">
<span class="dijitReset dijitInline" dojoattachpoint="iconNode">
<span class="dijitReset dijitToggleButtonIconChar">
</span>
</span>
<span class="dijitReset dijitInline dijitButtonText" id="dijit_form_Button_9_label" dojoattachpoint="containerNode">favouriteList</span>
</button>
Below is the code for buttonfix(this) function:
<script type="text/javascript">
function buttonfix(dojoButton) {
var button;
if(dojoButton.id==""){
button = dojoButton;
} else {
button=document.getElementById(dojoButton.id)
}
for(j=0; j<button.form.elements.length; j++)
if(button.form.elements[j].tagName == 'BUTTON' )
button.form.elements[j].disabled = true;
button.disabled=false;
}
</script>
so,can anyone provide me any other solution to this???
I might be misunderstanding the question, but...
The scroll upwards is probably because the form is posted, triggering a reload of the page. Perhaps you could try changing your onclick to:
onclick="buttonfix(this);return false"
This would prevent the submit.
Set scrollOnFocus:false within the properties of the dojo button - https://dojotoolkit.org/api/#1_10dijit_form_Button_scrollOnFocus

Categories